Code Monkey home page Code Monkey logo

Comments (5)

gxcare avatar gxcare commented on June 2, 2024 2

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.

from android-support-preference-v7-fix.

tylerwilson avatar tylerwilson commented on June 2, 2024 1

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.

from android-support-preference-v7-fix.

gregkorossy avatar gregkorossy commented on June 2, 2024

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.

from android-support-preference-v7-fix.

tylerwilson avatar tylerwilson commented on June 2, 2024

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).

from android-support-preference-v7-fix.

dynoChris avatar dynoChris commented on June 2, 2024

What is PreferenceFixTheme?

from android-support-preference-v7-fix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.