当前位置: 首页 > news >正文

Android AlertDialog圆角背景不生效的问题

一行解决:

window?.setBackgroundDrawableResource(android.R.color.transparent)

原文件:

/*** Created by Xinghai.Zhao* 自定义选择弹框*/
@SuppressLint("InflateParams", "MissingInflatedId")
class CustomDialog(context: Context?) : AlertDialog(context){var mCallBack: ClickCallBack? = nullvar mTextViewTitle: TextView? = nullvar mTextViewContent: TextView? = nullvar mEditText:EditText? = nullvar mEditTextMax:TextView? = nullvar mEditLayout: View? = nullvar mTextViewYes: TextView? = nullvar mTextViewNo: TextView? = nullvar mLine: View? = nullvar isEdit:Boolean = falseconstructor(context: Context?, title: String?, content: String?, callBack: ClickCallBack, isEditType:Boolean) : this(context) {mCallBack = callBackisEdit = isEditTypemTextViewTitle?.text = title?:""mTextViewContent?.text = content?:""if (isEdit){mEditLayout?.visibility = View.VISIBLE}else{mEditLayout?.visibility = View.GONE}}init {val inflate = LayoutInflater.from(context).inflate(R.layout.dialog_custom, null)setView(inflate)window?.setBackgroundDrawableResource(android.R.color.transparent)//设置点击别的区域不关闭页面setCancelable(false)mTextViewTitle = inflate.findViewById(R.id.dialog_custom_title)mTextViewContent = inflate.findViewById(R.id.dialog_custom_content)mEditText = inflate.findViewById(R.id.dialog_custom_edit)mEditTextMax = inflate.findViewById(R.id.dialog_custom_edit_max)mEditLayout = inflate.findViewById(R.id.dialog_custom_edit_layout)mTextViewYes = inflate.findViewById(R.id.dialog_custom_yes)mTextViewYes?.setOnClickListener{mCallBack?.onYesClick(this)}mTextViewNo = inflate.findViewById(R.id.dialog_custom_no)mTextViewNo?.setOnClickListener{dismiss()}mLine = inflate.findViewById(R.id.dialog_custom_line)}interface ClickCallBack {fun onYesClick(dialog: CustomDialog)}
}

layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/bg_set"android:orientation="vertical"><TextViewandroid:id="@+id/dialog_custom_title"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:padding="20dp"android:textColor="@color/black"android:textSize="18sp"android:textStyle="bold" /><TextViewandroid:id="@+id/dialog_custom_content"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:padding="30dp"android:textColor="@color/black"android:textSize="14sp" /><LinearLayoutandroid:id="@+id/dialog_custom_edit_layout"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:paddingBottom="20dp"android:visibility="gone"><EditTextandroid:id="@+id/dialog_custom_edit"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_marginStart="10dp"android:layout_weight="1"android:maxLength="10"android:maxLines="1"android:padding="10dp"android:textColor="@color/black"android:textSize="14sp" /><TextViewandroid:id="@+id/dialog_custom_edit_max"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginEnd="10dp"android:padding="10dp"android:textColor="@color/grey"android:textSize="12sp" /></LinearLayout><TextViewandroid:layout_width="match_parent"android:layout_height="1dp"android:background="@color/grey2" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:id="@+id/dialog_custom_no"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:gravity="center"android:padding="10dp"android:text="取消"android:textColor="@color/black"android:textSize="16sp" /><TextViewandroid:id="@+id/dialog_custom_line"android:layout_width="1dp"android:layout_height="match_parent"android:background="@color/grey2" /><TextViewandroid:id="@+id/dialog_custom_yes"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:gravity="center"android:padding="10dp"android:text="确定"android:textColor="@color/blue"android:textSize="16sp" /></LinearLayout>
</LinearLayout>

bg_set.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><corners android:radius="14dp" /> <!-- 圆角半径为10dp --><solid android:color="@color/white" /> <!-- 设置黑色背景并且70%不透明度 -->
</shape>

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 漏洞挖掘 | Selenium Grid 中的 SSRF
  • dockerfile案例
  • js中的条件控制语句
  • MySQL从入门到精通
  • 【智路】智路OS Perception Camera Service
  • 中间件安全(二)
  • B2B2CJava商城如何提高二次开发能力
  • IEC101、IEC103、IEC 104区别
  • 《黑神话悟空》开发框架与战斗系统解析
  • 达梦数据库sql日志说明
  • 深蓝学院-- 量产自动驾驶中的规划控制算法 小鹏
  • 监控易监测对象及指标之:全面监控GBase数据库
  • 【MySQL】MySQL和Workbench版本兼容问题
  • MATLAB绘图:4.统计图表
  • Microsoft Edge 五个神级插件
  • “大数据应用场景”之隔壁老王(连载四)
  • canvas 高仿 Apple Watch 表盘
  • CSS3 变换
  • Java基本数据类型之Number
  • Mysql优化
  • Node 版本管理
  • Promise面试题2实现异步串行执行
  • Python socket服务器端、客户端传送信息
  • Spark VS Hadoop:两大大数据分析系统深度解读
  • vue 个人积累(使用工具,组件)
  • 笨办法学C 练习34:动态数组
  • 分享几个不错的工具
  • 湖南卫视:中国白领因网络偷菜成当代最寂寞的人?
  • 力扣(LeetCode)22
  • 前端面试总结(at, md)
  • 世界上最简单的无等待算法(getAndIncrement)
  • 项目管理碎碎念系列之一:干系人管理
  • 深度学习之轻量级神经网络在TWS蓝牙音频处理器上的部署
  • Android开发者必备:推荐一款助力开发的开源APP
  • ​html.parser --- 简单的 HTML 和 XHTML 解析器​
  • ​MPV,汽车产品里一个特殊品类的进化过程
  • #### golang中【堆】的使用及底层 ####
  • #《AI中文版》V3 第 1 章 概述
  • #VERDI# 关于如何查看FSM状态机的方法
  • #每日一题合集#牛客JZ23-JZ33
  • (八)Flink Join 连接
  • (二刷)代码随想录第15天|层序遍历 226.翻转二叉树 101.对称二叉树2
  • (附源码)spring boot公选课在线选课系统 毕业设计 142011
  • (附源码)springboot优课在线教学系统 毕业设计 081251
  • (附源码)ssm基于jsp的在线点餐系统 毕业设计 111016
  • (附源码)ssm考生评分系统 毕业设计 071114
  • (附源码)计算机毕业设计SSM智能化管理的仓库管理
  • (转)一些感悟
  • * CIL library *(* CIL module *) : error LNK2005: _DllMain@12 already defined in mfcs120u.lib(dllmodu
  • .a文件和.so文件
  • .bat批处理(七):PC端从手机内复制文件到本地
  • .java 指数平滑_转载:二次指数平滑法求预测值的Java代码
  • .NET 2.0中新增的一些TryGet,TryParse等方法
  • .net 7和core版 SignalR
  • .NET Core工程编译事件$(TargetDir)变量为空引发的思考