consp1racy / android-support-preference

Android Preferences according to Material design specs
Apache License 2.0
331 stars 49 forks source link

How to change title and content colors dialog ListPreference #44

Closed goldmont closed 8 years ago

goldmont commented 8 years ago

Hi,

I'm using the latest version of your library. What values I should add in styles.xml to change the title, the content and the widget color? Thank you.

consp1racy commented 8 years ago

Hi,

The dialog opened by ListPreference is themed by the alertDialogTheme attribute defined in your activity theme. Please see the sample project for more info.

The alert dialog theme can inherit from Theme.AppCompat.Dialog.Alert or Theme.AppCompat.Light.Dialog.Alert for a dark or light base respectively. Then you override colorAccent with desired widget color and android:textColorPrimary with desired text color.

parmarravi commented 5 years ago

I am not able to modify the background color for the list Preference. I want to show the black color in dialog . Help me out what i am doing wrong here.

 <style name="AppCompatAlert" parent="Theme.AppCompat.Dialog.Alert">
        <item name="android:textColorPrimary">@color/white</item>
        <!-- Used for the background -->
        <item name="android:background">@color/greyBlack</item>
        <!-- Used for the buttons -->
        <item name="colorAccent">@color/greenLight</item>
        <item name="colorControlHighlight">@color/grey_light</item>
        <item name="android:textColor">@color/white</item>
        <item name="colorPrimary">@color/black</item>
        <item name="colorPrimaryDark">@color/black</item>
        <item name="android:popupBackground">@color/greyBlack</item>
        <item name="android:windowBackground">@color/greyBlack</item>
        <item name="android:itemBackground">@color/greyBlack</item>
        <item name="android:selectableItemBackground">@color/greyBlack</item>
    </style>

This is the theme for settings activity

<style name="AppThemeSettings" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/darkerGrey</item>
        <item name="colorPrimaryDark">@color/darkerGrey</item>
        <item name="colorAccent">#11b470</item>
        <item name="alertDialogCenterButtons">true</item>
        <item name="android:colorForeground">@color/gery_lighter</item>
        <item name="android:textColorPrimary">@color/white</item>
        <item name="android:textColor">@color/white</item>
        <item name="textColorAlertDialogListItem">@color/white</item>
        <item name="android:textColorSecondary">@color/grey_light</item>
        <item name="textAppearanceButton">@color/green</item>
        <item name="colorControlActivated">@color/greenLight</item>
        <item name="android:checkboxStyle">@style/AppTheme.Preference.Checkbox</item>
        <!--<item name="android:background">@color/blackDark</item>-->
        <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
        <item name="android:dialogTheme">@style/AppCompatAlert</item>
        <item name="android:alertDialogTheme">@style/AppCompatAlert</item>
        <item name="android:alertDialogStyle">@style/AppCompatAlert</item>
        <item name="android:textColorAlertDialogListItem">@color/black</item>
    </style>
consp1racy commented 5 years ago

Hi @parmarravi,

never, ever, put android:background to a theme. It will change background of everything that doesn't have a background already. Every nested layout will have a background, it's called overdraw and it's bad for performance.

AppCompat tints the dialog background drwable with android:colorBackground so it should work if you do this:

<style name="AppCompatAlert" parent="Theme.AppCompat.Dialog.Alert">
    <item name="android:colorBackground">@color/greyBlack</item>
</style>

Be careful with the android: prefix. AppCompat uses many attributes without it, for example popupBackground.

Remove the prefix from selectableItemBackground and provide a drawable that has a focused and pressed state (or use a ripple drawable on API 21+). Otherwise you won't get proper behavior when selecting items.

Finally, "how to style dialog background" is a question best suited for Stack Overflow so next time, please, start there. I mean, this really has nothing to do with the library, agreed?

Good luck!