修改黑色背景

第一种方式

直接使用AlertDialog.Builder的方法

AlertDialog dialog = new AlertDialog.Builder(this)                    .create();dialog.setInverseBackgroundForced(true);// 背景变成了白色

第二种方式

自定义一个布局,在dialog显示之后,重新设置dialog的内容view

AlertDialog dialog = new AlertDialog.Builder(this)                    .create();dialog.show();Window window = dialog.getWindow();window.setContentView(R.layout.custom_alert_dialog);// 设置背景透明window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

注意:一定要在show()方法之后重新设置布局。至于为什么,实践出真知

AlertDialog的圆角边框

设置修改Alertdialog黑色背景的第二种方式的布局文件R.layout.custom_alert_dialog的背景为圆角边框即可
下面是布局及圆角的代码
R.layout.custom_alert_dialog.xml

<?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_dialog"    android:paddingRight="20dp"    android:paddingLeft="20dp"    android:orientation="vertical">    <TextView        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:text="编辑"/>    <EditText        android:id="@+id/et_countDownWord"        android:layout_width="match_parent"        android:layout_height="wrap_content" />    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content">        <Button            android:layout_weight="1"            android:text="取消"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />        <Button            android:layout_weight="1"            android:text="确定"            android:layout_width="wrap_content"            android:layout_height="wrap_content" />    LinearLayout>LinearLayout>

圆角,bg_dialog.xml

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">    <corners android:radius="20dp"/>        <solid android:color="#ffffff"/>shape>

修改自https://www.cnblogs.com/yaowukonga/archive/2012/05/19/2508743.html

https://blog.csdn.net/csdnzouqi/article/details/84337004

更多相关文章

  1. Android——Canvas类的使用
  2. “layer-list” 和 “include”的使用
  3. Android学习笔记12:框架布局管理器FrameLayout
  4. Android自定义dialog主题样式解析
  5. 自定义控件和试图(部分原生api)下拉菜单
  6. Android原生音量控制
  7. Material Design详解 主题布局
  8. Android中GridView实现长按多选功能
  9. java化改造--xml布局文件转成java——学习整理

随机推荐

  1. Android(安卓)的一些提示框
  2. android studio 将背景设置为黑色或者白
  3. 从网上找的Android实用代码,记录备用
  4. Failed to Sync Gradle, could not find
  5. Android(java)学习笔记63:线程的调度
  6. Android中实现输入图片地址浏览图片操作
  7. android实现高性能,高并发,可延时线程池管
  8. Android利用ViewFlipper实现屏幕切换动画
  9. Android通过Movie展示Gif格式图片
  10. 整理 酷炫 Android(安卓)开源UI框架 刷新