AlertDialog造型 - 如何改变标题,邮件等方式(颜色) [英] AlertDialog styling - how to change style (color) of title, message, etc
问题描述
我已经打破我的头在这个颇有几分。我需要做的是,改变所有 AlertDialog
S的风格在我的Android应用程序 - 对话框的背景必须是白色的杂交和文本必须是黑色的杂交。我试图创造了很多的风格,主题,并从code,清单等,但没有成功应用,对于文字颜色 AlertDialog
里面。现在,我有codeS最简单的设置是这样的:
清单:
<应用 机器人:图标=@可绘制/ ic_launcher 机器人:标签=@字符串/ APP_NAME 机器人:主题=@风格/ AppTheme>
styles.xml:
<样式名称=AppTheme父=AppBaseTheme> <项目名称=机器人:alertDialogStyle> @风格/ DialogStyle< /项目> < /风格> <样式名称=DialogStyle父=@安卓风格/ Theme.Dialog> <! - 改变这些背景的东西工作正常 - > <项目名称=机器人:bottomBright> @android:彩色/白< /项目> <项目名称=机器人:bottomDark> @android:彩色/白< /项目> <项目名称=机器人:bottomMedium> @可绘制/ dialog_footer_bg< /项目> <项目名称=机器人:centerBright> @android:彩色/白< /项目> <项目名称=机器人:centerDark> @可绘制/ dialog_body_bg< /项目> <项目名称=机器人:centerMedium> @android:彩色/白< /项目> <项目名称=机器人:富布赖特> @色/橙色< /项目> <项目名称=机器人:fullDark> @色/橙色< /项目> <项目名称=机器人:百譓> @色/绿色< /项目> <项目名称=机器人:topDark> @可绘制/ dialog_header_bg< /项目>
下面列出的项目不工作(请阅读我已经把每一个元素上面的注释):
<! - panelBackground不获取设置为null,在它周围有一些方形 - > <项目名称=机器人:panelBackground> @空< /项目> <! - 设置此文字颜色似乎并没有什么效果都没有。消息,标题,按钮上的文字颜色,无论;没有什么变化。 - > <项目名称=机器人:文字颜色>#000000< /项目> <! - 也试过用textAppearance,如下所示。没有工作 - > <项目名称=?安卓textAppearance>机器人:ATTR / textColorPrimaryInverse< /项目> <! - 也试图改变textAppearancePrimary,都无济于事 - > <项目名称=机器人:textColorPrimary>#000000< /项目> !< - 还需要更改对话框的标题文字,试了一下,如下所示,力工: - > <项目名称=机器人:windowTitleStyle> @风格/ DialogWindowTitle< /项目> < /风格>
的DialogWindowTitle定义如下:
<样式名称=DialogWindowTitle> <项目名称=?安卓textAppearance>机器人:ATTR / textAppearanceMediumInverse< /项目> < /风格>
所以,这些都不是工作。谁能告诉我什么,我可以做错误的,哪能:
- 更改文本颜色信息(内容文本)
- 更改标题字体颜色
- 删除 面板背景
注:我需要支持的API 8(2.2)以上。另外,我通过大多数的相关问题已经走到这里,和谷歌组,但想不通,虽然我在我的鼻子感觉它吧!
编辑:添加截图:
您需要定义一个主题为您AlertDialog,并引用它在你活动的主题。属性是 alertDialogTheme
,而不是 alertDialogStyle
。像这样的:
<样式名称=Theme.YourTheme父=@安卓风格/ Theme.Holo>
...
<项目名称=机器人:alertDialogTheme> @风格/ YourAlertDialogTheme< /项目>
< /风格>
<样式名称=YourAlertDialogTheme>
<项目名称=机器人:windowBackground> @android:彩色/透明< /项目>
<项目名称=机器人:windowContentOverlay> @空< /项目>
<项目名称=机器人:windowIsFloating>真< /项目>
<项目名称=机器人:windowAnimationStyle> @android:款式/ Animation.Dialog< /项目>
<项目名称=机器人:windowMinWidthMajor> @android:扪/ dialog_min_width_major< /项目>
<项目名称=机器人:windowMinWidthMinor> @android:扪/ dialog_min_width_minor< /项目>
<项目名称=机器人:windowTitleStyle> ...< /项目>
<项目名称=机器人:textAppearanceMedium> ...< /项目>
<项目名称=机器人:borderlessButtonStyle> ...< /项目>
<项目名称=机器人:buttonBarStyle> ...< /项目>
< /风格>
您将能够改变颜色和外观文字为标题,邮件,你必须在每个区域的背景一定的控制。我写了一个博客文章详细步骤格调AlertDialog。
I've breaking my head over this quite a bit. What I need to do is, change the style of all AlertDialog
s in my android application - dialog background needs to be white-ish, and text needs to be black-ish. I tried creating a lot of styles, themes, and applying from the code, manifest, etc, but no success, with regard to the text colors inside the AlertDialog
. Right now, I have the simplest of codes, set like this:
Manifest:
<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>
The items listed below don't work (please read the comments I've put above each element):
<!-- 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>
The DialogWindowTitle is defined as follows:
<style name="DialogWindowTitle"> <item name="android:textAppearance">?android:attr/textAppearanceMediumInverse</item> </style>
So none of these is working. Can anyone tell me what I could be doing wrong, and how can I:
- Change text color for messages (content text)
- Change title text color
- Remove the panel background
Note: I need to support API 8 (2.2) upwards. Also, I've went through most of the related question here, and google groups, but can't figure out, though I have a feeling its right under my nose!
Edit: adding screenshot:
You need to define a Theme for your AlertDialog and reference it in your Activity's theme. The attribute is alertDialogTheme
and not alertDialogStyle
. Like this:
<style name="Theme.YourTheme" parent="@android:style/Theme.Holo">
...
<item name="android:alertDialogTheme">@style/YourAlertDialogTheme</item>
</style>
<style name="YourAlertDialogTheme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
<item name="android:windowTitleStyle">...</item>
<item name="android:textAppearanceMedium">...</item>
<item name="android:borderlessButtonStyle">...</item>
<item name="android:buttonBarStyle">...</item>
</style>
You'll be able to change color and text appearance for the title, the message and you'll have some control on the background of each area. I wrote a blog post detailing the steps to style an AlertDialog.
这篇关于AlertDialog造型 - 如何改变标题,邮件等方式(颜色)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!