Change dialogMessage color of EditTextPreference

Zorgan :

I have a custom preference, which extends EditTextPreference:

class DeleteAccountPreference(context: Context, attrs: AttributeSet) : EditTextPreference(context, attrs) {
    ...
}  

preferences.xml

<my.app.DeleteAccountPreference
    android:layout="@layout/preference_click"
    android:key="delete_account"
    android:title="Delete Account"
    android:dialogMessage="@string/delete_account_message" />

Which I have applied a custom theme to:

styles.xml

<style name="BaseTheme" parent="Theme.AppCompat.NoActionBar">
    ...        
    <item name="alertDialogTheme">@style/AlertDialogTheme</item>
</style>

<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:background">@color/colorIcons</item>
    <item name="colorPrimary">@color/colorLightBlack</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorPrimaryDark">@color/colorExit</item>
    <item name="editTextColor">@color/colorAccent</item>
    <item name="android:textColorHint">#000000</item>
    <item name="android:windowBackground">@color/colorPrimary</item>
</style>

However no matter what item I add to AlertDialogTheme, I can't seem to change the dialogMessage color (which is white) shown below.

Any idea what <item> I need to add to change this color?

azizbekian :

You should apply android:textColorSecondary to the theme of your activity:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ...
    <item name="android:textColorSecondary">#FF5722</item>
</style>

Then you'll get an orange message content:

Note, this will affect every other view in this activity, which relies on textColorSecondary attribute. I've tried to make this change affect only specific preference, unfortunately PreferenceFragmentCompat will disregard provided Context and will use context of the activity, hence passing around a ContextThemeWrapper with custom theme won't take effect. I guess this is a conscious decision from Google team, meaning that all of the attributes inside this preference screen should adapt to same color scheme.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=122100&siteId=1