当前位置: 首页 > 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>

http://www.lryc.cn/news/441969.html

相关文章:

  • 探讨基于AI技术的相亲交友系统设计与实现
  • (2024.9.20)Endnote插入的参考文献字号太大怎么办?
  • DataGrip在Windows和MacOS平台上的快捷键
  • CSS---序号使用css设置,counter-reset、counter-increment、content配合实现备注文案的序号展示
  • Liquor 表达式引擎基本使用
  • AI美女屠版小红书火了,被当真人推流,颜值博主慌了
  • 本地搭建我的世界服务器(JAVA)简单记录
  • 哪个快?用300万个图斑测试ArcGIS Pro的成对叠加与经典叠加
  • 超详细!百分百安装成功pytorch,建议收藏
  • web基础—dvwa靶场(四)​File Inclusion
  • 【Python】练习:控制语句(二)第1关
  • Vue3 : Pinia的性质与作用
  • 对接金蝶云星空调用即时库存信息查询API
  • pretrain Llama3
  • [附源码]SpringBoot+VUE+Java实现人脸识别系统
  • 数据库_解决SQL Server数据库log日志过大,清理日志文件方法
  • 引领长期投资新篇章:价值增长与财务安全的双重保障
  • 灾备技术演进之路 | 虚拟化无代理备份只能挂载验证和容灾吗?只能无代理恢复吗?且看科力锐升级方案
  • PowerShell install 一键部署Oracle23ai
  • 【Kubernetes】常见面试题汇总(二十五)
  • 【踩坑】装了显卡,如何让显示器从主板和显卡HDMI都输出
  • spring boot启动报错:so that it conforms to the canonical names requirements
  • unix中如何查询和修改进程的资源限制
  • 【LeetCode每日一题】——401.二进制手表
  • ROM和RAM的区别
  • tomcat的配置
  • SQL使用IN进行分组统计时如何将不存在的字段显示为0
  • MoCo对比损失
  • 01_WebRtc_一对一视频通话
  • 【小程序 - 大智慧】深入微信小程序的渲染周期