如何将对话框中的项目颜色从黑色更改为白色?

huangapple go评论69阅读模式
英文:

How to change the color of an dialog item from black to white?

问题

以下是已翻译的部分:

我正在使用以下主题进行对话框设计:

<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:textColorSecondary">@color/colorWhite</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:background">@color/colorPrimary</item>
    <item name="android:textColor">@color/colorWhite</item>
    <item name="android:textColorAlertDialogListItem">@color/colorWhite</item>
</style>

一切都正常,但项目文本颜色无法改变。我需要它是白色的,但出于某种原因,它保持不变。如何将文本更改为白色?谢谢

编辑:

这是我的AppTheme:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorSecondary">@color/colorWhite</item>
</style>

如何将对话框中的项目颜色从黑色更改为白色?

英文:

I'm using the following theme for my dialog:

&lt;style name=&quot;AlertDialogStyle&quot; parent=&quot;Theme.AppCompat.Light.Dialog.Alert&quot;&gt;
    &lt;item name=&quot;android:textColorSecondary&quot;&gt;@color/colorWhite&lt;/item&gt;
    &lt;item name=&quot;colorAccent&quot;&gt;@color/colorAccent&lt;/item&gt;
    &lt;item name=&quot;android:background&quot;&gt;@color/colorPrimary&lt;/item&gt;
    &lt;item name=&quot;android:textColor&quot;&gt;@color/colorWhite&lt;/item&gt;
    &lt;item name=&quot;android:textColorAlertDialogListItem&quot;&gt;@color/colorWhite&lt;/item&gt;
&lt;/style&gt;

Everything works but the item text color. I need to be white, but for some reason, it remains back. How can I change that text to be white? Thanks

如何将对话框中的项目颜色从黑色更改为白色?

Edit:

Here is my AppTheme:

&lt;style name=&quot;AppTheme&quot; parent=&quot;Theme.AppCompat.Light.NoActionBar&quot;&gt;
    &lt;item name=&quot;colorPrimary&quot;&gt;@color/colorPrimary&lt;/item&gt;
    &lt;item name=&quot;colorPrimaryDark&quot;&gt;@color/colorPrimaryDark&lt;/item&gt;
    &lt;item name=&quot;colorAccent&quot;&gt;@color/colorAccent&lt;/item&gt;
    &lt;item name=&quot;android:textColorSecondary&quot;&gt;@color/colorWhite&lt;/item&gt;
&lt;/style&gt;

答案1

得分: 1

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <item name="textColorAlertDialogListItem">@color/colorWhite</item>
</style>

或者

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <item name="alertDialogTheme">@style/AlertDialogStyle</item>
</style>
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    ...
    <item name="textColorAlertDialogListItem">@color/colorWhite</item>
    <!--
    <item name="android:textColor">@color/colorWhite</item>
    -->
</style>

也可以更改android:textColor,但这会改变对话窗口中的所有文本颜色。

英文:

You may refer https://stackoverflow.com/questions/17230933/alertdialog-theme-how-to-change-item-text-color

&lt;style name=&quot;AppTheme&quot; parent=&quot;Theme.AppCompat.Light.NoActionBar&quot;&gt;
    ...
    &lt;item name=&quot;textColorAlertDialogListItem&quot;&gt;@color/colorWhite&lt;/item&gt;
&lt;/style&gt;

or

&lt;style name=&quot;AppTheme&quot; parent=&quot;Theme.AppCompat.Light.NoActionBar&quot;&gt;
    ...
    &lt;item name=&quot;alertDialogTheme&quot;&gt;@style/AlertDialogStyle &lt;/item&gt;
&lt;/style&gt;

&lt;style name=&quot;AlertDialogStyle&quot; parent=&quot;Theme.AppCompat.Light.Dialog.Alert&quot;&gt;
    ...
    &lt;item name=&quot;textColorAlertDialogListItem&quot;&gt;@color/colorWhite&lt;/item&gt;
    &lt;!--
    &lt;item name=&quot;android:textColor&quot;&gt;@color/colorWhite&lt;/item&gt;
    --&gt;
&lt;/style&gt;

Also you can change android:textColor, but it will change all the text color in Dialog Window

答案2

得分: 0

使用自定义的对话框样式创建对话框。

new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.AlertDialogStyle))

将以下行添加到您的应用主题中。

<item name="android:alertDialogTheme">@style/AlertDialogStyle</item>
<item name="android:alertDialogStyle">@style/AlertDialogStyle</item>
英文:

Use your custom DialogBox Style while creating DialogBox.

new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.AlertDialogStyle))

Add these lines into your app theme

&lt;item name=&quot;android:alertDialogTheme&quot;&gt;@style/AlertDialogStyle&lt;/item&gt;
&lt;item name=&quot;android:alertDialogStyle&quot;&gt;@style/AlertDialogStyle&lt;/item&gt;

huangapple
  • 本文由 发表于 2020年8月4日 17:04:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/63243523.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定