gpt4 book ai didi

android - 警报对话框文本颜色的 XML 属性

转载 作者:太空狗 更新时间:2023-10-29 14:31:00 24 4
gpt4 key购买 nike

我正在应用一个主题:

  <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 属性可以解决这个问题。我已经尝试了大多数我能想到的方法,但没有一个起作用。

有什么想法吗?

最佳答案

hooked82 是对的。在 Honeycomb 之前,Android 不支持 AlertDialogs 的文本样式。您可以将样式应用于 AlertDialog,但它会忽略文本样式。

这是一个很好的 SO 答案,对您来说是一个很好的解决方案:How to change theme for AlertDialog

这是一篇非常有用的博客文章,它使用上面提出的解决方案来正确设置 AlertDialog 的样式。

关于android - 警报对话框文本颜色的 XML 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6946150/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com