I'm having few custom themes in my styles.xml
Now whenever the activity takes the theme, it uses the colorPrimary, colorPrimaryDark and colorAccent values.
For my layout's background I'm using ?attr/colorAccent, so it can pick the background color based on the selected theme.
If I use any of the above values it works fine. But I want to define a custom item value for my background color.
I tried like this below but it didn't worked. any ideas to make it work ?
My custom theme with custom value:
<style name = "customTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#4285f4</item>
<item name="colorPrimaryDark">#2C75F2</item>
<item name="colorAccent">#E1FFC7</item>
<item name="customBgColor">#d3d3d3</item>
</style>
And I want to use it in layout's style as
<style name="layoutStyle" >
<item name="android:background">?attr/customBgColor</item>
</style>
Create a
attrs.xml
file shown in image.customTheme 1
customTheme 2
Setting Color to
TextView
as example.You can use it in similar way in any widget anywhere.
This
TextView
is used in below activity.Want to set theme dynamically.
For multiple activities you have set theme for each of them separately.