android - 警报对话框主题不从活动主题继承`windowBackground`
问题描述
在我的应用程序中,我有这个主题styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">@color/neon_green</item>
<item name="android:windowBackground">@color/black_17</item>
</style>
但该属性windowBackground
不会导致对话框背景发生变化。对话框背景颜色仍然是白色。但是,对话框文本的neon_green
突出显示颜色确实出现了。
只有不改变的背景颜色。
AlertDialog.Builder builder =
new AlertDialog.Builder(new ContextThemeWrapper(act, R.style.AppTheme));
builder.setMessage("text")
.setPositiveButton("pos ", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton("neg", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
builder.create().show();
解决方案
我刚刚将它添加到我的样式中
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColor">@color/white</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:background">@color/black_17</item>
</style>
然后我将样式传递给构建器
AlertDialog.Builder builder =
new AlertDialog.Builder(act,
R.style.AppCompatAlertDialogStyle);
推荐阅读
- python - Instagram API-如何使用 python 获取 **Instagram Account** 上的 **likes 和 comments** 总数?
- dolphindb - 如何在 dolphindb 中调试时写入日志文件
- python - RFE:如何更改评分标准?
- c# - 无法在 MStest 中使用垫片来伪造 .net 中的 SharePoint
- java - Zookeeper curator - 连接到集群中的服务器
- c - 如何使用 C 中的结构正确增加日期并输出以下日期
- excel - 使用 VBA Excel 将 RTF 文本转换为纯文本
- c# - EF Core 使用存储过程加载相关实体
- c# - 将 blob 上传到存储帐户时出现异常
- asp.net - 将 Byte[] 转换为流文件 asp.net