Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to style dialog from DialogPreference #52

Closed
tylerwilson opened this issue Oct 24, 2016 · 5 comments
Closed

How to style dialog from DialogPreference #52

tylerwilson opened this issue Oct 24, 2016 · 5 comments
Labels

Comments

@tylerwilson
Copy link

I apologize if this is not directly related to Preference-V7-Fix - though perhaps it is something it could assist with in the future.

I have been trying to style the popup dialogs from ListPreference, but nothing is working. I have tried overriding dialogPreferenceStyle, alertDialogStyle, etc. but it is always ignored. (I changed my main preferences to use a dark background and white text, which then causes many of the text and controls in the dialogs to be white and white and thus invisible).

Is there an global dialog style in the Fix lib that might help be accomplish this?

@tylerwilson tylerwilson changed the title How to style dialog from ListPreference How to style dialog from DialogPreference Oct 24, 2016
@gxcare
Copy link

gxcare commented Oct 24, 2016

I lost a lot of time trying to figure how to implement this and at the result is quite simple, if you just want all the dialogs to have the same style.

Set a theme like this to the activity implementing the preferences:

`

<!-- Accent color for preferences activity ........... -->
<color name="preference_accent">@color/app_accent</color>

<!-- App theme for preferences activity ........... -->
<style name="AppThemePreferences" parent="@style/PreferenceFixTheme">
    <item name="colorPrimary">@color/app_primary</item>
    <item name="colorPrimaryDark">@color/app_primary_dark</item>
    <item name="colorAccent">@color/app_accent</item>
    <item name="android:windowBackground">@color/app_background</item>
    <item name="actionModeBackground">@color/app_action_mode_background</item>
    <item name="colorControlHighlight">@color/app_control_highlight</item>
    <item name="colorControlActivated">@color/app_control_activated</item>
    <!-- AppCompat Dialog Attributes -->
    <item name="dialogTheme">@style/AppCompatDialog</item>
    <item name="alertDialogTheme">@style/AppCompatAlert</item>
</style>
<!-- Generic Dialog Theme -->
<style name="AppCompatDialog" parent="Theme.AppCompat.Dialog">
    <!-- Used for the title and text -->
    <item name="android:textColorPrimary">@color/dialog_text</item>
    <!-- Used for the background -->
    <item name="android:background">@color/dialog_background</item>
    <!-- Used for the buttons -->
    <item name="colorAccent">@color/dialog_button</item>
    <item name="colorControlHighlight">@color/dialog_control_highlight</item>

    <item name="colorPrimary">@color/app_primary</item>
    <item name="colorPrimaryDark">@color/app_primary_dark</item>
</style>

<!-- Alert Dialog Theme -->
<style name="AppCompatAlert" parent="Theme.AppCompat.Dialog.Alert">
    <item name="android:textColorPrimary">@color/dialog_text</item>
    <!-- Used for the background -->
    <item name="android:background">@color/dialog_background</item>
    <!-- Used for the buttons -->
    <item name="colorAccent">@color/dialog_button</item>
    <item name="colorControlHighlight">@color/dialog_control_highlight</item>

    <item name="colorPrimary">@color/app_primary</item>
    <item name="colorPrimaryDark">@color/app_primary_dark</item>
</style>

`

Take the above code as an example as I took it directly from my app, but it is working properly for me.

@gregkorossy
Copy link
Owner

gregkorossy commented Oct 24, 2016

What @giccisw writes is the standard way of overriding AlertDialog styles. It was part of the lib as the AlertDialog wouldn't use the accent color from the main theme, but has been removed since in v24.2.0.0 because the Android team fixed this behavior.

@tylerwilson
Copy link
Author

So to be clear @Gericop: I should be able to set the background of the displayed AlertDialog that is displayed from any DialogPreference-derived Preference? Because I have not been able to effect any changes to the dialogs. I will be trying to tweak my existing style to match what @giccisw has above (I thought mine was pretty much the same, but it could be one character off I suppose).

@tylerwilson
Copy link
Author

Okay, I got it working. Thank you both so much. I was using "android:alertDialogTheme" instead of the plain "alertDialogTheme". Frustrating. I also was not using the PreferenceFixTheme as a base for my Preference Theme which perhaps has an effect as well.

@dynoChris
Copy link

What is PreferenceFixTheme?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants