I used this to change the accent color in EditText in the Material Theme:
<style name="AppThemeSub" parent="#android:style/Theme.Material.Light">
<item name="android:colorPrimary">#color/colorPrimary</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:textColorPrimary">#color/white</item>
<item name="android:colorAccent">#color/colorPrimary</item>
</style>
And this to change the ProgressBar color:
<style name="AppThemeWeb" parent="#android:style/Theme.Material.Light">
<item name="android:colorPrimary">#color/colorPrimary</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:textColorPrimary">#color/white</item>
<item name="android:colorAccent">#color/white</item>
</style>
How I can use this in Holo Theme?
PS: I used the indeterminateDrawable in the layout of ProgressBar and not work with Holo Theme devices.
You have to use the AppCompat theme like this will behave as holo and you can set all material properties here in your value's direcotry style.xml. I have used this theme.
//My Customized Theme
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/myPrimaryColor</item>
<item name="colorPrimaryDark">#color/myPrimaryDarkColor</item>
<item name="colorAccent">#color/myAccentColor</item>
<item name="android:textColorPrimary">#color/myPrimaryTextColor</item>
<item name="android:textColorSecondary">#color/mySecondaryTextColor</item>
<item name="android:actionBarDivider">#color/myDividerColor</item>
<item name="android:windowActionModeOverlay">true</item>
</style>
Related
I'm using a custom theme for my app. When the dark mode is applied, some colors don't match the dark background at all.
For example, text buttons for dialogs:
According to the Material documentation, the text buttons use the Primary color.
But I've noticed that the default theme (the purple, blue-green one) uses some secondary color for the text buttons, which is what I'd like to achieve.
That dialog is popped up by a list preference, so I can't create a custom activity as dialog to replace it with its own style.
here is a sample theme of custom themed Dialog hope it helps you
<style name="Theme.App" parent="Theme.MaterialComponents.DayNight">
...
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="materialAlertDialogTheme">#style/ThemeOverlay.App.MaterialAlertDialog</item>
</style>
//here is importance part
<style name="ThemeOverlay.App.MaterialAlertDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="colorPrimary">#color/colorPrimaryDark</item>
<item name="colorSecondary">#color/colorSecondary</item>
<item name="colorSurface">#color/colorSurface</item>
<item name="colorOnSurface">#color/colorAccent</item>
<item name="alertDialogStyle">#style/MaterialAlertDialog.App</item>
<item name="materialAlertDialogTitleTextStyle">#style/MaterialAlertDialog.App.Title.Text</item>
<item name="buttonBarPositiveButtonStyle">#style/Widget.App.Button</item>
<item name="buttonBarNegativeButtonStyle">#style/Widget.App.Button</item>
</style>
<style name="MaterialAlertDialog.App" parent="MaterialAlertDialog.MaterialComponents">
<item name="shapeAppearance">#style/ShapeAppearance.App.MediumComponent</item>
</style>
// for title color
<style name="MaterialAlertDialog.App.Title.Text" parent="MaterialAlertDialog.MaterialComponents.Title.Text">
<item name="android:textColor">#color/color_dialog_buttons</item>
</style>
<style name="Widget.App.Button" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="materialThemeOverlay">#style/ThemeOverlay.App.Button</item>
<item name="shapeAppearance">#style/ShapeAppearance.App.SmallComponent</item>
</style>
// for button colors
<style name="ThemeOverlay.App.Button" parent="">
<item name="colorPrimary">#color/color_dialog_buttons</item>
</style>
<style name="ShapeAppearance.App.MediumComponent" parent="ShapeAppearance.MaterialComponents.MediumComponent">
<item name="cornerFamily">cut</item>
<item name="cornerSize">8dp</item>
</style>
<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">cut</item>
<item name="cornerSize">4dp</item>
</style>
I am using a custom theme for dialogs in my app.
The custom theme applies to the alert dialogs just fine.
But the theme does not apply on the preference dialogs like ListPreference, CheckboxPreference etc.
Currently i am applying the dialog theme using the materialAlertDialogTheme attribute like this:
Main app theme:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:navigationBarColor">?attr/colorPrimary</item>
<item name="android:windowTranslucentStatus">true</item>
<!-- Material Dialog theme -->
<item name="materialAlertDialogTheme">#style/ThemeOverlay.App.MaterialAlertDialog</item>
</style>
MaterialDialog styles:
<!-- Styles for Material Dialogs -->
<style name="ThemeOverlay.App.MaterialAlertDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="colorSurface">#android:color/white</item>
<item name="alertDialogStyle">#style/MaterialAlertDialog.App</item>
<item name="materialAlertDialogTitleTextStyle">#style/MaterialAlertDialog.App.Title.Text</item>
<item name="buttonBarPositiveButtonStyle">#style/Widget.App.PositiveButton</item>
</style>
<style name="MaterialAlertDialog.App" parent="MaterialAlertDialog.MaterialComponents">
<item name="shapeAppearance">#style/ShapeAppearance.App.MediumComponent</item>
</style>
<style name="MaterialAlertDialog.App.Title.Text" parent="MaterialAlertDialog.MaterialComponents.Title.Text">
<item name="android:textStyle">bold</item>
</style>
<style name="Widget.App.PositiveButton" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="materialThemeOverlay">#style/ThemeOverlay.App.Button</item>
<item name="shapeAppearance">#style/ShapeAppearance.App.SmallComponent</item>
<item name="android:textAllCaps">false</item>
</style>
<style name="ThemeOverlay.App.Button" parent="">
<item name="colorPrimary">#android:color/black</item>
</style>
<style name="ShapeAppearance.App.MediumComponent" parent="ShapeAppearance.MaterialComponents.MediumComponent">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">8dp</item>
</style>
<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">4dp</item>
</style>
Here is a dialog perfectly getting themed:
And here is a preference dialog which is not getting themed (notice the corners):
I have also tried setting alertDialog attribute in the main theme, but its not working.
Any suggestions?
What I needed to resolve this issue was to add
<item name="alertDialogTheme">#style/AppTheme.AlertDialogTheme</item>
to my base style and
<style name="AppTheme.AlertDialogTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="dialogCornerRadius">20dp</item>
</style>
as a style. Sad that this made my whole AlertDialog.Builder to MaterialAlertDialogBuilder migration somehow pointless (at least in the cases cornerFamily is rounded), hopefully we will see a better integration between preferences and material theme in future.
reference: https://www.reddit.com/r/androiddev/comments/dg8jfo/styling_androidx_preference_dialogs_using/
I´m Using com.android.support:appcompat-v7:22.1.1
This attribute android:buttonStyle is not setting that style for every button, I need to set android:theme="#style/AppTheme.Button" manually on each button.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:buttonStyle">#style/AppTheme.Button</item>
</style>
What do I need to do to set a general style for it?
Use buttonStyle insteadof android:buttonStyle in your theme
Similar to #danielgomezrico answer but without having two style files:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!-- android:buttonStyle for v21+ and buttonStyle for the rest -->
<item name="buttonStyle">#style/MyCustomButton</item>
<item name="android:buttonStyle">#style/MyCustomButton</item>
<item name="colorButtonNormal">#color/my_color_accent</item>
</style>
<style name="MyCustomButton" parent="Base.Widget.AppCompat.Button">
<item name="android:textColor">#ffffff</item>
</style>
I ended up setting background color with colorButtonNormal attribute and other style attributes with buttonStyle.
values/style.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/my_color_primary</item>
<item name="colorPrimaryDark">#color/my_color_primary_dark</item>
<item name="colorAccent">#color/my_color_accent</item>
</style>
<style name="AppTheme.Base">
<item name="colorButtonNormal">#color/my_color_accent</item>
<item name="buttonStyle">#style/Button</item>
</style>
<style name="Button" parent="Base.Widget.AppCompat.Button">
<item name="android:textColor">#color/my_color_white</item>
</style>
values-v21/style.xml
<style name="AppTheme.Base">
<item name="android:colorButtonNormal">#color/my_color_accent</item>
<item name="android:buttonStyle">#style/Button</item>
</style>
And then all the buttons have the background/text color I wanted without setting style on each one.
When i'm using the item actionBarStyle, colorPrimary doesn't set the color to red.
If i delete the item actionBarStyle, it works. How can i change my code to display the color?
<resources>
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<item name="actionBarStyle">#style/MyStyledActionBar</item>
<item name="colorPrimary">#color/red</item>
</style>
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
</style>
</resources>
The root of Widget.AppCompat.Light.ActionBar is Base.Widget.AppCompat.ActionBar, which doesn't apply a background attribute.
<style name="Base.Widget.AppCompat.ActionBar" parent="">
...
<item name="background">#null</item>
<item name="backgroundStacked">#null</item>
<item name="backgroundSplit">#null</item>
...
</style>
Instead your parent should be Widget.AppCompat.Light.ActionBar.Solid, so that you'll inherit the attributes from Base.Widget.AppCompat.Light.ActionBar.Solid, which applies the background attribute.
<style name="Base.Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">?attr/colorPrimary</item>
<item name="backgroundStacked">?attr/colorPrimary</item>
<item name="backgroundSplit">?attr/colorPrimary</item>
</style>
Alternatively, you could just apply the background attribute yourself.
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
<item name="background">?attr/colorPrimary</item>
</style>
I want to add a custom style that is for example purple in one theme and red in one other theme.
<style name="subtitle_layout" parent="#android:style/Theme.Holo.Light">
<item name="android:background">#color/purple</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">40sp</item>
</style>
<style name="subtitle_layout2" parent="#android:style/Theme.Holo.Light">
<item name="android:background">#color/black</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">80sp</item>
</style>
<style name="Theme1" parent="android:Theme.Holo.Light">
<item name="android:textColor">#color/black</item>
<item name="#style/subtitle_layout">#style/subtitle_layout</item>
</style>
<style name="Theme2" parent="android:Theme.Holo.Light">
<item name="android:textColor">#color/white</item>
<item name="#style/subtitle_layout">#style/subtitle_layout2</item>
</style>
The change of theme works because i see the change of text color, but instead of android:textColor i would like to put a style instead. But it doesn't work.
I guess you are trying to inherit existing styles to your theme, am I right? You can just set the style as your parent theme:
<style name="Theme1" parent="#style/subtitle_layout">
<item name="android:textColor">#color/black</item>
</style>