问题描述
我已经打破我的头在这个颇有几分。我需要做的是,改变所有 AlertDialog
S的风格在我的Android应用程序 - 对话框的背景必须是白色的杂交和文本必须是黑色的杂交。我试图创造了很多的风格,主题,并从code,清单等,但没有成功应用,对于文字颜色 AlertDialog
里面。现在,我有codeS最简单的设置是这样的:
清单:
styles.xml:
下面列出的项目不工作(请阅读我已经把每一个元素上面的注释):
的DialogWindowTitle定义如下:
所以,这些都不是工作。谁能告诉我什么,我可以做错误的,哪能:
- 更改文本颜色信息(内容文本)
- 更改标题字体颜色
- 删除面板背景
注:我需要支持的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:
styles.xml:
The items listed below don't work (please read the comments I've put above each element):
The DialogWindowTitle is defined as follows:
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 thepanel 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造型 - 如何改变标题,邮件等方式(颜色)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!