您的位置:首页 > 移动开发 > Android开发

改变Android中默认Dialog的样式

2017-01-04 15:20 239 查看
Android中默认的Dialog是黑白色的,有点丑啊!

在清单文件中application的标签属性中theme,默认的是:

android:theme="@style/AppTheme"


<style name="AppTheme" parent="android:Theme.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>


默认Dialog的代码:

AlertDialog.Builder builder = new AlertDialog.Builder(ShopsDetailActivity.this);
builder.setMessage("是否退出当前绑定的社区店?");
builder.setTitle("来米汇");
builder.setPositiveButton("是", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//清空表中所有记录
SQLdb.execSQL("DELETE FROM picturetable");
finish();
}
});
builder.setNegativeButton("否", null);
builder.show();


默认的Dialog是这样的:



是不是很丑啊!

如果我们想改变默认Dialog的样式,可以重新定义style

<style name="customHoloLight" parent="@android:style/Theme.Holo.Light">
<item name="android:windowNoTitle">true</item>
</style>


在application中引用

android:theme="@style/customHoloLight"


效果是这样的:



是不是清爽很多!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 应用 标签