【问题标题】:How to apply light theme for the activity and keep the dark theme for the dialogs at the same time?如何为活动应用浅色主题并同时为对话框保留深色主题?
【发布时间】:2012-10-09 03:32:45
【问题描述】:
有没有一种方法可以为 PreferenceActivity 应用自定义样式,该样式将从 Theme.Sherlock.Light 或 Theme.Light 继承,并为 preferenceDialog 和 AlertDialogs 保留深色样式?我可以轻松地从应用灯光样式中排除对话框吗?如果没有,我应该设置哪些属性,以及在浅色主题中分隔线、文本活动、非活动、标题和副标题等中使用的默认颜色的参数是什么?谢谢。
【问题讨论】:
标签:
android
android-alertdialog
android-dialog
android-theme
【解决方案1】:
我通过将活动主题更改为浅色解决了这个问题,然后我以编程方式将警报对话框的主题设置为深色,内置 android 样式:
this.setTheme(android.R.style.Theme_Holo_Dialog);
由于 PreferenceDialog 继承自 Dialog,它也将此主题设置为所有 PreferenceDialogs。
更具体地说,为特定对话框添加样式,您可以使用 ContextThemeWrapper,如 android 源代码中的 Dialog.java 中使用的那样:
builder = new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_DeviceDefault_Dialog))