英文:
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:
<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>
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:
<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>
答案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
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="textColorAlertDialogListItem">@color/colorWhite</item>
</style>
or
<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>
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
<item name="android:alertDialogTheme">@style/AlertDialogStyle</item>
<item name="android:alertDialogStyle">@style/AlertDialogStyle</item>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论