在线直播源码,自定义AlertDialog设置宽高并去掉默认的边框
在线直播源码,自定义AlertDialog设置宽高并去掉默认的边框
1、先写一个自定义的AlertDialog。
1 | <br>package com.phone.common_library.dialog;<br> <br>import android.annotation.SuppressLint;<br>import android.content.Context;<br>import android.content.DialogInterface;<br>import android.view.Gravity;<br>import android.view.LayoutInflater;<br>import android.view.View;<br>import android.view.Window;<br>import android.view.WindowManager;<br>import android.widget.TextView;<br> <br>import androidx.annotation.NonNull;<br>import androidx.appcompat.app.AlertDialog;<br> <br>import com.phone.common_library.R;<br>import com.phone.common_library.callback.OnCommonSingleParamCallback;<br>import com.phone.common_library.callback.OnItemViewClickListener;<br> <br> public class StandardDialog {<br> <br> private AlertDialog alertDialog;<br> <br> private TextView tevTitle;<br> private TextView tevContent;<br> private View viewHorizontalLine;<br> private TextView tevCancel;<br> private View viewVerticalLine;<br> private TextView tevOk;<br> <br> <br> @SuppressLint( "RestrictedApi" )<br> public StandardDialog(@NonNull Context context) {<br> View view = LayoutInflater.from(context).inflate(R.layout.dialog_standard, null, false);<br> tevTitle = (TextView) view.findViewById(R.id.tev_title);<br> tevContent = (TextView) view.findViewById(R.id.tev_content);<br> viewHorizontalLine = (View) view.findViewById(R.id.view_horizontal_line);<br> tevCancel = (TextView) view.findViewById(R.id.tev_cancel);<br> viewVerticalLine = (View) view.findViewById(R.id.view_vertical_line);<br> tevOk = (TextView) view.findViewById(R.id.tev_ok);<br> <br> <br> //设置R.style.dialog_decimal_style和setView(view, 0, 0, 0, 0)就可以去掉<br> //AlertDialog的默认边框,此时AlertDialog的layout的宽高就是AlertDialog的宽高<br> alertDialog = new AlertDialog.Builder(context, R.style.standard_dialog_style)<br> .setView(view)<br> .create();<br> tevCancel.setOnClickListener(v -> {<br> onItemViewClickListener.onItemClickListener(0, v);<br> });<br> tevOk.setOnClickListener(v -> {<br> onItemViewClickListener.onItemClickListener(1, v);<br> });<br> alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {<br> @Override<br> public void onCancel(DialogInterface dialog) {<br> onCommonSingleParamCallback.onSuccess("");<br> }<br> });<br> alertDialog.show();<br> <br> Window window = alertDialog.getWindow();<br> if (window != null) {<br>// window.setBackgroundDrawableResource(android.R.color.transparent);<br> // 取消这些边框的关键代码<br> window.setBackgroundDrawable(null);<br> window.setGravity(Gravity.CENTER);<br>// window.setWindowAnimations(R.style.PictureThemeDialogWindowStyle);<br> WindowManager.LayoutParams params = window.getAttributes();<br> window.setAttributes(params);<br> //把 DecorView 的默认 padding 取消,同时 DecorView 的默认大小也会取消<br> window.getDecorView().setPadding(0, 0, 0, 0);<br> }<br> }<br> <br> public void setTevContent(String content) {<br> tevContent.setText(content);<br> }<br> <br> public void setTevCancelHide() {<br> viewVerticalLine.setVisibility(View.GONE);<br> tevCancel.setVisibility(View.GONE);<br> }<br> <br> public void setCannotHide() {<br> alertDialog.setCancelable(false);<br> alertDialog.setCanceledOnTouchOutside(false);<br> }<br> <br> public void hideStandardDialog() {<br> if (alertDialog != null) {<br> alertDialog.dismiss();<br> alertDialog = null;<br> }<br> }<br> <br> private OnItemViewClickListener onItemViewClickListener;<br> <br> public void setOnItemViewClickListener(OnItemViewClickListener onItemViewClickListener) {<br> this.onItemViewClickListener = onItemViewClickListener;<br> }<br> <br> private OnCommonSingleParamCallback<String> onCommonSingleParamCallback;<br> <br> public void setOnCommonSingleParamCallback(OnCommonSingleParamCallback<String> onCommonSingleParamCallback) {<br> this.onCommonSingleParamCallback = onCommonSingleParamCallback;<br> }<br> <br>} |
2、AlertDialog的layout。
1 | <br><?xml version= "1.0" encoding= "utf-8" ?><br><LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" <br> xmlns:tools= "http://schemas.android.com/tools" <br> android:layout_width= "@dimen/dp_300" <br> android:layout_height= "@dimen/dp_240" <br> android:background= "@drawable/corners_14_color_white" <br> android:orientation= "vertical" ><br> <br> <!-- 注意:这里一定要写一个布局,这个布局和本布局的根布局宽高相同,要写固定宽高,不要使用match_parent,不然宽高可能会失效 --><br> <LinearLayout<br> android:layout_width= "@dimen/dp_300" <br> android:layout_height= "@dimen/dp_240" <br> android:orientation= "vertical" <br> tools:ignore= "UselessParent" ><br> <br> <View<br> android:layout_width= "match_parent" <br> android:layout_height= "@dimen/dp_20" /><br> <br> <TextView<br> android:layout_width= "match_parent" <br> android:layout_height= "@dimen/dp_40" <br> android:layout_gravity= "center_horizontal" <br> android:gravity= "center" <br> android:paddingStart= "@dimen/dp_10" <br> android:paddingEnd= "@dimen/dp_10" <br> android:text= "Decimal" <br> android:textColor= "@color/blue" <br> android:textSize= "@dimen/sp_16" /><br> <br> <View<br> android:layout_width= "match_parent" <br> android:layout_height= "@dimen/dp_20" /><br> <br> <EditText<br> android:id= "@+id/edt_input" <br> android:layout_width= "@dimen/dp_240" <br> android:layout_height= "@dimen/dp_40" <br> android:layout_gravity= "center_horizontal" <br> android:background= "@drawable/corners_14_color_white_stroke_1_color_80000000" <br> android:gravity= "center_vertical" <br> android:paddingStart= "@dimen/dp_15" <br> android:paddingEnd= "@dimen/dp_15" <br> android:textColor= "@color/colorBlack333" <br> android:textSize= "@dimen/sp_16" /><br> <br> <View<br> android:layout_width= "match_parent" <br> android:layout_height= "@dimen/dp_20" /><br> <br> <FrameLayout<br> android:layout_width= "@dimen/dp_200" <br> android:layout_height= "@dimen/dp_40" <br> android:layout_gravity= "center_horizontal" ><br> <br> <TextView<br> android:id= "@+id/tev_cancel" <br> android:layout_width= "@dimen/dp_80" <br> android:layout_height= "@dimen/dp_40" <br> android:layout_gravity= "start" <br> android:background= "@drawable/corners_14_color_white_stroke_1_color_80000000" <br> android:gravity= "center" <br> android:paddingStart= "@dimen/dp_10" <br> android:paddingEnd= "@dimen/dp_10" <br> android:text= "cancel" <br> android:textColor= "@color/color_80000000" <br> android:textSize= "@dimen/sp_16" /><br> <br> <TextView<br> android:id= "@+id/tev_confirm" <br> android:layout_width= "@dimen/dp_80" <br> android:layout_height= "@dimen/dp_40" <br> android:layout_gravity= "end" <br> android:background= "@drawable/corners_14_color_white_stroke_1_color_blue" <br> android:gravity= "center" <br> android:paddingStart= "@dimen/dp_10" <br> android:paddingEnd= "@dimen/dp_10" <br> android:text= "confirm" <br> android:textColor= "@color/blue" <br> android:textSize= "@dimen/sp_16" /><br> <br> </FrameLayout><br> </LinearLayout><br> <br></LinearLayout> |
以上就是在线直播源码,自定义AlertDialog设置宽高并去掉默认的边框, 更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
2022-04-26 短视频app制作,自定义标题栏形式和样式
2022-04-26 直播平台软件开发,完整截取整个屏幕的截图方式
2022-04-26 直播平台制作,文字过多时,自动折叠显示查看更多选项