【发布时间】:2013-04-18 12:44:29
【问题描述】:
我已经为此烦恼了很久。我需要做的是,在我的 android 应用程序中更改所有 AlertDialogs 的样式 - 对话框背景需要是白色的,文本需要是黑色的。关于AlertDialog 中的文本颜色,我尝试从代码、清单等创建很多样式、主题和应用,但没有成功。现在,我有最简单的代码,设置如下:
清单:
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" >
styles.xml:
<style name="AppTheme" parent="AppBaseTheme"> <item name="android:alertDialogStyle">@style/DialogStyle</item> </style> <style name="DialogStyle" parent="@android:style/Theme.Dialog"> <!-- changing these background stuff works fine --> <item name="android:bottomBright">@android:color/white</item> <item name="android:bottomDark">@android:color/white</item> <item name="android:bottomMedium">@drawable/dialog_footer_bg</item> <item name="android:centerBright">@android:color/white</item> <item name="android:centerDark">@drawable/dialog_body_bg</item> <item name="android:centerMedium">@android:color/white</item> <item name="android:fullBright">@color/orange</item> <item name="android:fullDark">@color/orange</item> <item name="android:topBright">@color/green</item> <item name="android:topDark">@drawable/dialog_header_bg</item>
下面列出的项目不起作用(请阅读我在每个元素上方放置的 cmets):
<!-- panelBackground is not getting set to null, there is something squarish around it --> <item name="android:panelBackground">@null</item> <!-- Setting this textColor doesn't seem to have any effect at all. Messages, title, button text color, whatever; nothing changes. --> <item name="android:textColor">#000000</item> <!-- Also tried with textAppearance, as follows. Didn't work --> <item name="android:textAppearance">?android:attr/textColorPrimaryInverse</item> <!-- Also tried changing textAppearancePrimary, to no avail --> <item name="android:textColorPrimary">#000000</item> <!-- Also need to change the dialog title text, tried it as follows, dint work: --> <item name="android:windowTitleStyle">@style/DialogWindowTitle</item> </style>
DialogWindowTitle 定义如下:
<style name="DialogWindowTitle"> <item name="android:textAppearance">?android:attr/textAppearanceMediumInverse</item> </style>
所以这些都不起作用。谁能告诉我我做错了什么,我该怎么做:
- 更改消息的文本颜色(内容文本)
- 更改标题文本颜色
- 删除 面板背景
注意:我需要向上支持 API 8 (2.2)。另外,我在这里和谷歌群组中查看了大部分相关问题,但无法弄清楚,虽然我感觉它就在我的鼻子底下!
编辑:添加截图:
【问题讨论】:
-
你能提供一张它目前的外观截图吗?
-
@Ahmad:已添加屏幕截图
-
我想知道你是如何改变这些背景颜色的。使用完全相同的代码,我无法针对 API 级别 9 复制彩色 AlertDialog。您是否以某种特殊方式应用了主题或样式?您的目标和最低 sdk 级别设置为多少?
-
奇怪...不知何故我让它工作了,我不知道怎么做。非常感谢这篇文章,我为此挠了好几个小时。对于任何搜索的人来说,这个问题/答案是在 Android API 级别自定义 AlertDialogs 的权威方法
-
...但由于某种原因,如果我在任何运行 Android >= 3.0 的设备上运行此代码,对话框颜色不会改变。因此,对于 >2.3.3 和
标签: android android-alertdialog android-theme android-styles