問題描述
我正在嘗試更改對話框中的文本顏色,最常見的是 AlertDialog.我已經嘗試了這些頁面上的所有解決方案:
I'm trying to change the text color in dialog boxes, most commonly AlertDialog. I've tried every solution at these pages:
AlertDialog 樣式 - 如何更改樣式(顏色)標題、消息等
如何更改 AlertDialog 標題的顏色及其下方線條的顏色
如何更改 AlertDialog 的主題
大多數解決方案在低于 5.0 但高于它的情況下工作,它們似乎沒有任何效果.我應該為 5.0+ 更改哪些不同的屬性?
Most solutions work BELOW 5.0 but above it, and they don't seem to have any effect. What different attributes should I be changing for 5.0+?
我的應用的父主題是Theme.AppCompat.Light.NoActionBar"
The parent theme of my app is "Theme.AppCompat.Light.NoActionBar"
推薦答案
在你的情況下,我認為對話框主題可以工作.
In your case, I think the dialog theme would work.
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.YourDialogStyle;
您可以像上面的代碼一樣指定對話框主題.
You can specify your dialog theme just like the code above.
<style name="YourDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="android:colorAccent">@color/primary</item>
<item name="android:textColor">@color/accent</item>
<item name="android:textColorPrimary">@color/primary_dark</item>
</style>
這里是Dialog的主題示例.
Here is the example of theme for Dialog.
- android:colorAccent 會影響您的負面或正面按鈕的文本顏色.
- android:textColor會影響你的對話框標題文字顏色.
- android:textColorPrimary 會影響對話框的消息顏色.
- android:colorAccent will affect your text colors of negative or positive buttons.
- android:textColor will affect your title text color of dialog.
- android:textColorPrimary will affect your message color of dialog.
另一種選擇是您可以為對話框制作自己的自定義布局.
Another option is you can make your own custom layout for the dialog.
這篇關于在 5.0+ 上更改對話框文本顏色的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!