直播系統程式碼,點選選擇欄,彈出各個選項

zhibo系統開發發表於2022-01-05

直播系統程式碼,點選選擇欄,彈出各個選項實現的相關程式碼

實現程式碼如下:

activity_popup_window.xml按鈕

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
    xmlns:app="
    xmlns:tools="
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".PopupWindowActivity">
    <Button
        android:id="@+id/btn_popupWindow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="PopupWindow" />
</LinearLayout>


自定義彈出的檢視layout_pop.xml,也可以用RecycleView或者ListView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:id="@+id/tv_good"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:text="好"
        android:textColor="@color/gray"
        android:textSize="20sp" />
    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="@color/gray" />
    <TextView
        android:id="@+id/tv_not_too_bad"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:text="還行"
        android:textColor="@color/gray"
        android:textSize="20sp" />
    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="@color/gray" />
    <TextView
        android:id="@+id/tv_bad"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:text="不好"
        android:textColor="@color/gray"
        android:textSize="20sp" />
</LinearLayout>

PopupWindowActivity類實現程式碼如下:

public class PopupWindowActivity extends AppCompatActivity {
    private Button btn_popupWindow;
    private PopupWindow popupWindow;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup_window);
        btn_popupWindow = findViewById(R.id.btn_popupWindow);
        btn_popupWindow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                View popup_view = LayoutInflater.from(PopupWindowActivity.this).inflate(R.layout.layout_pop, null);
                TextView textView = popup_view.findViewById(R.id.tv_good);
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        popupWindow.dismiss();
                        Toast.makeText(PopupWindowActivity.this, "好", Toast.LENGTH_SHORT).show();
                    }
                });
                popupWindow = new PopupWindow(popup_view, btn_popupWindow.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);
                //設定彈出視窗應該接收外部觸控事件
                popupWindow.setOutsideTouchable(true);
                //設定可聚焦
                popupWindow.setFocusable(true);
                popupWindow.showAsDropDown(btn_popupWindow);
            }
        });
    }
}

以上就是直播系統程式碼,點選選擇欄,彈出各個選項實現的相關程式碼, 更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2850774/,如需轉載,請註明出處,否則將追究法律責任。

相關文章