改变AlertDialog默认背景
16lz
2021-01-25
安卓自带的AlertDialog太丑了有木有?黑色的背景很难看,今天实现的是怎么自定义style实现改变AlertDialog背景
首先在values/styles.xml文件中增加如下style
<style name="AlertDialog" parent="@android:Theme.DeviceDefault.Light.Dialog"><!-- 这里设置背景为透明,为了隐藏边框 --> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item><!-- 这里是修改顶部标题背景颜色,具体颜色自己定,可以是图片 --> <item name="android:topDark">@color/white</item> <!-- 这里是修改内容区域背景颜色 --><item name="android:centerDark">@color/white</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item></style>
具体引用代码:
public void showDeleteDiaog(final Account a) {//这里的构造函数使用两个参数,第二个参数即为设置样式AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.AlertDialog);builder.setMessage("撤销该记录?").setCancelable(false).setTitle("提示").setPositiveButton("确定", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int id) {try {db.deleteAccount(String.valueOf(a.getId()));MyUtil.showToast(AccountActivity.this, "撤销成功!");initData();} catch (Exception e) {MyUtil.showToast(AccountActivity.this, "撤销失败!");}dialog.cancel();}}).setNegativeButton("取消", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int id) {dialog.cancel();}});builder.show();}
实际样式如下:
更多相关文章
- Android,去除Dialog的边框
- Android(安卓)输入法框弹出 背景上移或压缩问题
- 【Android】Toast大全
- Github学习之EasyTabs打造绚丽TabLayout+ViewPager滑动动画集合
- android开发中圆形按钮的实现
- android 设置Spinner文字标题颜色 字体大小样式
- Android(安卓)POI操作office文档
- Android(安卓)夜间模式的设置以及需要注意的地方
- Android(安卓)自定义View 慢慢画一个不同颜色扇形的圆,点击圆上不