我的应用程序适用于黑暗和清晰的主题。但是在高于5.1的android系统中,对话框和日期选择器的文本不会更改其颜色,甚至会始终保持白色,甚至放置特定的主题。
我在stackoverflow中阅读了此内容,并根据所说的内容进行了更改,但没有任何效果。
这是我的风格:
v21 \ styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="BaseAppTheme.Dark" parent="Theme.AppCompat">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:alertDialogTheme">@style/CustomDialogAlert</item>
<item name="android:datePickerStyle">@style/CustomDialogAlert</item>
</style>
<style name="BaseAppTheme.Light" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:alertDialogTheme">@style/CustomDialogAlert</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:datePickerStyle">@style/CustomDialogAlert</item>
</style>
<style name="CustomDialogAlert" parent="@android:style/Widget.Material.Light.DatePicker">
<item name="colorAccent">@color/colorPrimaryDark
</item> <!-- gets applied to positive/neutral/negative buttons -->
<item name="android:textColor">@color/colorPrimaryDark</item>
<item name="android:textColorPrimary">@color/colorPrimaryDark</item>
<item name="android:textColorSecondary">@color/colorPrimaryDark
</item> <!-- gets applied to the message text-->
<item name="android:background">@color/colorPrimaryDark</item>
<item name="textColorAlertDialogListItem">@color/colorPrimaryDark
</item> <!-- if the alert's got a list instead of a message -->
<item name="android:headerBackground">@color/caldroid_black</item>
</style>
<style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog">
<item name="android:datePickerStyle">@style/CustomDialogAlert</item>
</style>
</resources>
样式:
<resources>
<!-- Base application theme. -->
<style name="BaseAppTheme.Dark" parent="@style/Theme.AppCompat">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="BaseAppTheme.Light" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<!--TEMA CLARO-->
<style name="AppTheme.Light" parent="BaseAppTheme.Light">
<item name="colorPrimary">@color/colorPrimary_light</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark_light</item>
<item name="colorAccent">@color/color_accent_light</item>
<item name="actionModeStyle">@style/Widget.ActionMode.Light</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:alertDialogTheme">@style/AlertDialogCustom</item>
<item name="android:windowBackground">@color/background_light</item>
<item name="android:colorBackground">@color/background_light</item>
<item name="alertDialogTheme">@style/CustomDialogAlert</item>
<!-- Text Color -->
<item name="android:textColor">@color/text_primary_light</item>
<item name="android:textColorPrimary">@color/text_primary_light</item>
<item name="android:textColorSecondary">@color/text_secondary_light</item>
<item name="android:textColorHint">@color/text_hint_light</item>
<item name="android:textColorPrimaryInverse">@color/text_primary_dark</item>
<item name="android:textColorSecondaryInverse">@color/text_secondary_dark</item>
<item name="background_noticias">@color/background_noticias_light</item>
<item name="color_noticias_titulo">@color/button_default_light</item>
<item name="color_noticias_subtitulo">@color/text_primary_light</item>
<!-- Drawables -->
<item name="marca_osasco_small">@drawable/marca_osascosmall</item>
<item name="marca_osasco_splash_small">@drawable/ic_splash_osasco</item>
<item name="drawer_text_color">@drawable/drawer_text_color_light</item>
<item name="bg_circulo">@drawable/bg_circulo_light</item>
<!-- Componentes nativos android-->
<item name="buttonStyle">@style/Widget.Custom.Button.Light</item>
<!-- <item name="colorButtonNormal">@color/button_default_light</item>
<item name="color_button_default">@color/button_default_light</item>-->
<!-- Componentes APP -->
<item name="divider_color">@color/divider_light</item>
<!-- Icones -->
<item name="ic_info_24dp">@drawable/ic_info_black_24dp</item>
<item name="ic_forum_24dp">@drawable/ic_forum_black_24dp</item>
<item name="ic_brightness_3_24dp">@drawable/ic_brightness_3_black_24dp</item>
<item name="ic_person_24dp">@drawable/ic_person_black_24dp</item>
<item name="ic_chevron_right_24dp">@drawable/ic_chevron_right_black_24dp</item>
<item name="ic_business_24dp">@drawable/ic_business_black_24dp</item>
<item name="ic_work_24dp">@drawable/ic_work_black_24dp</item>
<item name="ic_shopping_basket_24dp">@drawable/ic_shopping_basket_black_24dp</item>
<item name="ic_assignment_24dp">@drawable/ic_assignment_black_24dp</item>
<item name="ic_attach_money_24dp">@drawable/ic_attach_money_black_24dp</item>
<item name="ic_security_24dp">@drawable/ic_security_black_24dp</item>
<item name="ic_group_24dp">@drawable/ic_group_black_24dp</item>
<item name="ic_receipt_24dp">@drawable/ic_receipt_black_24dp</item>
<item name="ic_keyboard_arrow_down">@drawable/ic_keyboard_arrow_down_black_24dp</item>
<item name="ic_keyboard_arrow_up">@drawable/ic_keyboard_arrow_up_black_24dp</item>
<item name="ic_check_24dp">@drawable/ic_check_white_24dp</item>
<item name="ic_arrow_drop_down_24dp">@drawable/ic_arrow_drop_down_black_24dp</item>
<item name="ic_edit_24dp">@drawable/ic_edit_black_24dp</item>
<item name="ic_delete_forever_24dp">@drawable/ic_delete_forever_white_24dp</item>
<item name="ic_location_24dp">@drawable/ic_location_on_black_24dp</item>
<!--Icones Agenda -->
<item name="ic_description_24dp">@drawable/ic_description_black_24dp</item>
<item name="ic_alarm_add_24dp">@drawable/ic_alarm_add_black_24dp</item>
<item name="ic_schedule_24dp">@drawable/ic_schedule_black_24dp</item>
<item name="ic_date_range_24dp">@drawable/ic_date_range_black_24dp</item>
<item name="ic_search_24dp">@drawable/ic_search_black_24dp</item>
</style>
<!--TEMA ESCURO-->
<style name="AppTheme.Dark" parent="BaseAppTheme.Dark">
<!-- Base Colors -->
<item name="colorPrimary">@color/colorPrimary_dark</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark_dark</item>
<item name="colorAccent">@color/color_accent_dark</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:windowBackground">@color/background_dark</item>
<item name="android:colorBackground">@color/background_dark</item>
<!-- Text Color -->
<item name="android:textColor">@color/text_primary_dark</item>
<item name="android:textColorPrimary">@color/text_primary_dark</item>
<item name="android:textColorSecondary">@color/text_secondary_dark</item>
<item name="android:textColorHint">@color/text_hint_dark</item>
<item name="android:textColorPrimaryInverse">@color/text_primary_light</item>
<item name="android:textColorSecondaryInverse">@color/text_secondary_light</item>
<item name="background_noticias">@color/background_noticias_dark</item>
<item name="color_noticias_titulo">@color/text_primary_dark</item>
<item name="color_noticias_subtitulo">@color/text_primary_dark</item>
<item name="background_cell_item_agenda">@color/background_cell_item_agenda_dark</item>
<!-- Drawables -->
<item name="marca_osasco_small">@drawable/marca_osascosmall_darktheme</item>
<item name="marca_osasco_splash_small">@drawable/ic_splash_osasco_darktheme</item>
<item name="drawer_text_color">@drawable/drawer_text_color_dark</item>
<item name="bg_circulo">@drawable/bg_circulo_dark</item>
<!-- Componentes -->
<item name="buttonStyle">@style/Widget.Custom.Button.Dark</item>
<item name="colorButtonNormal">@color/button_default_dark</item>
<item name="color_button_default">@color/button_default_dark</item>
<item name="divider_color">@color/divider_dark</item>
<!-- Icones -->
<item name="ic_info_24dp">@drawable/ic_info_white_24dp</item>
<item name="ic_forum_24dp">@drawable/ic_forum_white_24dp</item>
<item name="ic_brightness_3_24dp">@drawable/ic_brightness_3_white_24dp</item>
<item name="ic_person_24dp">@drawable/ic_person_white_24dp</item>
<item name="ic_chevron_right_24dp">@drawable/ic_chevron_right_white_24dp</item>
<item name="ic_business_24dp">@drawable/ic_business_white_24dp</item>
<item name="ic_work_24dp">@drawable/ic_work_white_24dp</item>
<item name="ic_shopping_basket_24dp">@drawable/ic_shopping_basket_white_24dp</item>
<item name="ic_assignment_24dp">@drawable/ic_assignment_white_24dp</item>
<item name="ic_attach_money_24dp">@drawable/ic_attach_money_white_24dp</item>
<item name="ic_security_24dp">@drawable/ic_security_white_24dp</item>
<item name="ic_group_24dp">@drawable/ic_group_white_24dp</item>
<item name="ic_receipt_24dp">@drawable/ic_receipt_white_24dp</item>
<item name="ic_keyboard_arrow_down">@drawable/ic_keyboard_arrow_down_white_24dp</item>
<item name="ic_keyboard_arrow_up">@drawable/ic_keyboard_arrow_up_white_24dp</item>
<item name="ic_check_24dp">@drawable/ic_check_white_24dp</item>
<item name="ic_arrow_drop_down_24dp">@drawable/ic_arrow_drop_down_white_24dp</item>
<item name="ic_edit_24dp">@drawable/ic_edit_white_24dp</item>
<item name="ic_delete_forever_24dp">@drawable/ic_delete_forever_white_24dp</item>
<item name="ic_location_24dp">@drawable/ic_location_on_white_24dp</item>
<!--Icones Agenda -->
<item name="ic_description_24dp">@drawable/ic_description_white_24dp</item>
<item name="ic_alarm_add_24dp">@drawable/ic_alarm_add_white_24dp</item>
<item name="ic_schedule_24dp">@drawable/ic_schedule_white_24dp</item>
<item name="ic_date_range_24dp">@drawable/ic_date_range_white_24dp</item>
<item name="ic_search_24dp">@drawable/ic_search_white_24dp</item>
</style>
<!-- ActionMode Themes -->
<style name="Widget.ActionMode" parent="@style/Widget.AppCompat.ActionMode">
<item name="background">@color/colorPrimaryDark_dark</item>
</style>
<style name="Widget.ActionMode.Light" parent="@style/Widget.AppCompat.ActionMode">
<item name="background">@color/colorPrimaryDark_light</item>
</style>
<!-- Toolbar Themes -->
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="searchViewStyle">@style/CustomSearchViewStyle</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColor">@android:color/primary_text_light</item>
</style>
<style name="spinner" parent="android:Widget.TextView.SpinnerItem">
<item name="android:textAppearance">?android:textAppearanceMedium</item>
</style>
<!-- BOTOES -->
<style name="Base.Widget.Custom.Button" parent="Widget.AppCompat.Button">
<item name="android:minHeight">48dp</item>
</style>
<style name="Widget.Custom.Button.Dark" parent="Base.Widget.Custom.Button">
<item name="android:textColor">@color/text_primary_dark</item>
<item name="colorButtonNormal">@color/button_default_dark</item>
</style>
<style name="Widget.Custom.Button.Light" parent="Base.Widget.Custom.Button">
<item name="android:textColor">@color/text_primary_dark</item>
<item name="colorButtonNormal">@color/button_default_light</item>
</style>
<style name="Widget.Custom.Button.Red" parent="Base.Widget.Custom.Button">
<item name="android:textColor">@color/text_primary_dark</item>
<item name="colorButtonNormal">@color/button_red</item>
</style>
<style name="Widget.Custom.Button.White" parent="Base.Widget.Custom.Button">
<item name="android:textColor">@color/color_accent_light</item>
<item name="colorButtonNormal">@color/button_white</item>
</style>
<style name="Widget.Custom.Button.Accent" parent="Base.Widget.Custom.Button">
<item name="android:textColor">@color/text_primary_dark</item>
<item name="colorButtonNormal">@color/color_accent_light</item>
</style>
<style name="CustomSearchViewStyle" parent="Widget.AppCompat.SearchView" />
<!--TEXTVIEW CUSTOM-->
<style name="Widget.Custom.TextView.White" parent="Base.Widget.Custom.TextView">
<item name="android:textColor">@color/color_nfe_azul_escuro</item>
</style>
<style name="Base.Widget.Custom.TextView" parent="TextAppearance.AppCompat.Widget.TextView.SpinnerItem"></style>
<style name="MineCustomTabText" parent="TextAppearance.Design.Tab">
<item name="android:textSize">11dp</item>
</style>
<style name="AlertDialogCustom">
<item name="android:text">#0000FF</item>
<item name="android:textColor">#0000FF</item>
</style>
<!-- <style name="CustomDialogAlert" parent="android:Theme.Material.Light.Dialog">
<item name="colorAccent">@color/colorPrimaryDark</item> <!– gets applied to positive/neutral/negative buttons –>
<item name="android:textColor">@color/colorPrimaryDark</item>
<item name="android:textColorPrimary">@color/colorPrimaryDark</item>
<item name="android:textColorSecondary">@color/colorPrimaryDark</item> <!– gets applied to the message text–>
<item name="android:background">@color/colorPrimaryDark</item>
<item name="textColorAlertDialogListItem">@color/colorPrimaryDark</item> <!– if the alert's got a list instead of a message –>
</style>-->
</resources>
浅色主题始终使文本保持白色,因此例如不会出现“取消”和“确定”按钮。
图片:
https://photos.app.goo.gl/KtfFzHzhGnKQK6qH6
如果我更改按钮按钮样式的文本颜色,则文本将以我放置的颜色显示,但是系统按钮的文本也会更改,不仅对话框也将更改。
谢谢