警报对话框文本颜色的 XML 属性
我正在应用一个主题:
<style name="myAlertTheme" parent="@android:style/AlertDialog">
<item name="android:textColor">#ff000000</item>
</style>
<style name="RadioButton" parent="@android:style/Widget.CompoundButton.RadioButton">
<item name="android:textColor">#ff000000</item>
</style>
<style name="HSDroidStyle" parent="android:Theme">
<item name="android:background">#ffd3d3d3</item>
<item name="android:textColor">#ff000000</item>
<item name="android:textSize">20dp</item>
<item name="android:radioButtonStyle">@style/RadioButton</item>
</style>
但是当我创建警报时,文本显示为白色而不是黑色。要创建我正在使用的警报:
AlertDialog alertDialog = new AlertDialog.Builder(
new ContextThemeWrapper(act, R.style.myAlertTheme)).create();
alertDialog.setTitle(title);
alertDialog.setMessage(msg);
alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (exitOnFailure) mainAct.finish();
return;
} });
alertDialog.show();
现在,如果我更改 myAlertTheme 中的大小,但不更改标题或文本,则按钮中的“确定”会更改。所以我猜测还有其他一些 textColor 属性可以解决这个问题。我已经尝试了大部分我能想到的方法,但没有一个有效。
有什么想法吗?
I'm applying a theme:
<style name="myAlertTheme" parent="@android:style/AlertDialog">
<item name="android:textColor">#ff000000</item>
</style>
<style name="RadioButton" parent="@android:style/Widget.CompoundButton.RadioButton">
<item name="android:textColor">#ff000000</item>
</style>
<style name="HSDroidStyle" parent="android:Theme">
<item name="android:background">#ffd3d3d3</item>
<item name="android:textColor">#ff000000</item>
<item name="android:textSize">20dp</item>
<item name="android:radioButtonStyle">@style/RadioButton</item>
</style>
But when I create an Alert, the text shows up as white instead of black. To create the alert I'm using:
AlertDialog alertDialog = new AlertDialog.Builder(
new ContextThemeWrapper(act, R.style.myAlertTheme)).create();
alertDialog.setTitle(title);
alertDialog.setMessage(msg);
alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (exitOnFailure) mainAct.finish();
return;
} });
alertDialog.show();
Now the "OK" in the button changes if I change the size in the myAlertTheme, but not the title or the text. So I'm guessing that there is some other textColor attribute that addresses this. I've tried most of the ones I can think of, but none of them work.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
hooked82 是对的。在 Honeycomb 之前,Android 不正确支持 AlertDialogs 的文本样式。您可以将样式应用于 AlertDialog,但它会忽略文本样式。
这是一个很好的答案,对您来说是一个很好的解决方案: 如何更改 AlertDialog 的主题
这是一篇非常有用的博客文章,它使用上面提出的解决方案来正确设置 AlertDialog 的样式。
hooked82 is right. Prior to Honeycomb, Android did not support text styling properly for AlertDialogs. You could apply styles to an AlertDialog, but it would ignore the text styles.
Here's a good SO answer that would prove to be a good solution for you: How to change theme for AlertDialog
Here's a really useful blog post that uses the propsed solution above to style an AlertDialog properly.
AFAIK 没有办法修改标题/消息文本颜色(如果我错了,请纠正我)。因此,执行此操作的一种方法是为 AlertDialog 创建自定义视图并执行如下操作:
AFAIK there isn't a way to modify the Title/Message text colors (Please correct me if I'm wrong). So one way of doing this would be to create a custom view for your AlertDialog and do something like the following:
尝试使用以下语句声明
AlertDialog
:Try to declare the
AlertDialog
using this statement: