直播系统代码,点击选择栏,弹出各个选项

直播系统代码,点击选择栏,弹出各个选项实现的相关代码

实现代码如下:

activity_popup_window.xml按钮

 

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

自定义弹出的视图layout_pop.xml,也可以用RecycleView或者ListView

 

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

​PopupWindowActivity类实现代码如下:

 

1
<br>public class PopupWindowActivity extends AppCompatActivity {<br>    private Button btn_popupWindow;<br>    private PopupWindow popupWindow;<br>    @Override<br>    protected void onCreate(Bundle savedInstanceState) {<br>        super.onCreate(savedInstanceState);<br>        setContentView(R.layout.activity_popup_window);<br>        btn_popupWindow = findViewById(R.id.btn_popupWindow);<br>        btn_popupWindow.setOnClickListener(new View.OnClickListener() {<br>            @Override<br>            public void onClick(View view) {<br>                View popup_view = LayoutInflater.from(PopupWindowActivity.this).inflate(R.layout.layout_pop, null);<br>                TextView textView = popup_view.findViewById(R.id.tv_good);<br>                textView.setOnClickListener(new View.OnClickListener() {<br>                    @Override<br>                    public void onClick(View view) {<br>                        popupWindow.dismiss();<br>                        Toast.makeText(PopupWindowActivity.this, "好", Toast.LENGTH_SHORT).show();<br>                    }<br>                });<br>                popupWindow = new PopupWindow(popup_view, btn_popupWindow.getWidth(), ViewGroup.LayoutParams.WRAP_CONTENT);<br>                //设置弹出窗口应该接收外部触摸事件<br>                popupWindow.setOutsideTouchable(true);<br>                //设置可聚焦<br>                popupWindow.setFocusable(true);<br>                popupWindow.showAsDropDown(btn_popupWindow);<br>            }<br>        });<br>    }<br>}

 

以上就是直播系统代码,点击选择栏,弹出各个选项实现的相关代码, 更多内容欢迎关注之后的文章

 

posted @   云豹科技-苏凌霄  阅读(56)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示