• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Themes Theme inheritance

Hi,

I am currently doing multi-variant app and I came across an issue when I am not really sure what is the best solution for it.

I can't seem to grasp how to avoid redeclaring color attributes in themes that "can't" inherit from my main theme.

For example, classic AlertDialog - theme for it inherits from AppCompat/MaterialComponents and if I would want to style/theme the dialog(color-wise) I would have to copy all the attributes I intend to use from my main theme.

Is this just the way it has to be? (I am slightly aware that ThemeOverlays might be able to ease this but not researched it fully yet)
 
For example, classic AlertDialog - theme for it inherits from AppCompat/MaterialComponents and if I would want to style/theme the dialog(color-wise) I would have to copy all the attributes I intend to use from my main theme.
Well this is how I theme the AlertDialog. Hopefully this'll help you.

In the styles.xml file I add a Dialog theme as follows:
XML:
<style name="DialogTheme" parent="Theme.AppCompat.Dialog.Alert">
    <item name="colorAccent">#BDBDBD</item>
    <item name="android:background">#424242</item>
</style>

This just changes attributes from the parent theme "Theme.AppCompat.Dialog.Alert". You can add other attributes to the theme if you like. To put it plainly, this creates one theme for all your AlertDialogs.

Then to use the theme, you just reference it in java like so:
Java:
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogTheme);
 
Back
Top Bottom