直播系统代码,自定义平台私聊对话框
直播系统代码,自定义平台私聊对话框实现的相关代码
1.定义dialog.xml (res/layout/dialog.xml)
1 | <?xml version= "1.0" encoding= "utf-8" ?><br><RelativeLayout 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> <br> <RelativeLayout<br> android:layout_width= "250sp" <br> android:layout_height= "270sp" <br> android:layout_centerInParent= "true" ><br> <br> <TextView<br> android:id= "@+id/dialog_title" <br> android:layout_width= "wrap_content" <br> android:layout_height= "35sp" <br> android:layout_alignParentTop= "true" <br> android:layout_centerHorizontal= "true" <br> android:layout_marginTop= "15sp" <br> android:textColor= "#333333" <br> android:textSize= "17sp" /><br> <br> <TextView<br> android:id= "@+id/dialog_message" <br> android:layout_width= "wrap_content" <br> android:layout_height= "160sp" <br> android:layout_centerInParent= "true" <br> android:layout_marginTop= "65sp" <br> android:textColor= "#333333" <br> android:textSize= "17sp" /><br> <br> <LinearLayout<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:layout_alignParentBottom= "true" <br> android:layout_centerHorizontal= "true" <br> android:layout_marginTop= "30sp" <br> android:layout_marginBottom= "20sp" <br> android:orientation= "horizontal" ><br> <br> <LinearLayout<br> android:id= "@+id/dialog_confirm" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" ><br> <br> <TextView<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:background= "@drawable/confirm_button_style" <br> android:gravity= "center" <br> android:text= "确定" <br> android:textColor= "@color/white" <br> android:textSize= "18sp" /><br> </LinearLayout><br> <br> <LinearLayout<br> android:id= "@+id/dialog_cancel" <br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:layout_marginLeft= "22sp" ><br> <br> <TextView<br> android:layout_width= "wrap_content" <br> android:layout_height= "wrap_content" <br> android:background= "@drawable/cancel_button_style" <br> android:gravity= "center" <br> android:text= "取消" <br> android:textColor= "@color/teal_200" <br> android:textSize= "18sp" /><br> </LinearLayout><br> </LinearLayout><br> <br> </RelativeLayout><br></RelativeLayout> |
2. 设置确定、取消按钮的background
上文的dialog.xml中,确定和取消按钮都是TextView,所以需要自定义按钮的背景
1 | <br>confirm_button_style.xml (所有的color需要自定义)<br><?xml version= "1.0" encoding= "utf-8" ?><br><shape xmlns:android= "http://schemas.android.com/apk/res/android" <br> android:shape= "rectangle" ><br> <corners android:radius= "1000sp" /><br> <solid android:color= "@color/teal_200" /><br> <stroke<br> android:width= "0.5sp" <br> android:color= "@color/colorAccent" /><br> <size android:width= "105sp" android:height= "40sp" /><br></shape><br>cancel_button_style.xml <br><?xml version= "1.0" encoding= "utf-8" ?><br><shape xmlns:android= "http://schemas.android.com/apk/res/android" <br> android:shape= "rectangle" ><br> <corners android:radius= "1000sp" /><br> <solid android:color= "@color/white" /><br> <stroke<br> android:width= "0.5sp" <br> android:color= "@color/teal_200" /><br> <size android:width= "105sp" android:height= "40sp" /><br></shape> |
3. 自定义dialog的使用
1 | final AlertDialog dialog = new AlertDialog.Builder(xxxClass.this).create();<br>dialog.setCancelable(false); //点击对话框以外的位置,不消失<br>dialog.show();<br> <br>Window window = dialog.getWindow();<br>window.setContentView(R.layout.dialog);<br>//标题<br>TextView title = window.findViewById(R.id.dialog_title);<br>title.setText("dialog_title");<br> <br>//内容<br>TextView message = window.findViewById(R.id.dialog_message);<br>message.setText("dialog_message ");<br> <br>//确定按钮<br>LinearLayout confirm = window.findViewById(R.id.dialog_confirm);<br>confirm.setOnClickListener(new View.OnClickListener() {<br> @Override<br> public void onClick(View v) {<br> //xxx<br> }<br>});<br> <br>//取消按钮<br>LinearLayout cancel = window.findViewById(R.id.dialog_cancel);<br>cancel.setOnClickListener(new View.OnClickListener() {<br> @Override<br> public void onClick(View v) {<br> //xxx<br> }<br>}); |
以上就是直播系统代码,自定义平台私聊对话框实现的相关代码, 更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现