I cannot seem to get what I want no matter how much reading I do on this subject - yet what I want is quite simple.
I am applying a global style to my app based on AppCompat NoActionBar. This gives white text and I want to change it to a dark colour. Here is my styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorAccent">#color/colorSecondary</item>
<item name="android:textColor">#ff4400</item>
</style>
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:background">#color/colorPrimary</item>
<item name="colorControlNormal">#android:color/white</item>
</style>
This is fine. The text colour is changed to a dark colour everywhere (set to red here so I can see what's happening). Unfortunately this also overrides all of the text colouring for buttons. Disabled buttons show the dark colour and there is no way to distinguish them from enabled buttons. I've tried applying styles to buttons but the textColor always overrides the disabled colour.
I'm at a bit of a loss as to how to proceed. I don't want to apply a selector on every button nor colour all the buttons individually by setting a style on each one. I want an overall global colour change - which Android seems to have made exceptionally difficult.
I eventually managed to get it to work. I had to use a selector. I provide my solution below.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorButtonNormal">#color/colorSecondary</item>
<item name="android:textColorPrimary">#color/primary_text_color_selector</item>
<item name="android:textColorSecondary">#color/secondary_text_color_selector</item>
<item name="alertDialogTheme">#style/ThemeDialog</item>
</style>
<style name="ThemeDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">#color/primary_text_color_selector</item>
<item name="android:background">#color/colorTertiary</item>
</style>
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:background">#color/colorPrimary</item>
<item name="colorControlNormal">#android:color/white</item>
</style>
Related
How to increase the text size of RadioGroup in AlertDialog made using setSingleChoiceItems?
This is what we tried but did not work.
<style name="DialogButtonStyle" parent="Widget.Material3.Button.TextButton.Dialog" tools:keep="#style/DialogButtonStyle">
<item name="android:textColor">#color/orange</item>
</style>
<!-- AlertDialog theme on both light and night mode -->
<style name="AppDialog" parent="ThemeOverlay.Material3.MaterialAlertDialog" tools:keep="#style/AppDialog">
<!-- Background color -->
<!--<item name="colorSurface">#color/colorWhite_Primary</item>-->
<!-- Message color -->
<item name="colorOnSurfaceVariant">#color/white_black</item>
<item name="buttonBarPositiveButtonStyle">#style/DialogButtonStyle</item>
<item name="buttonBarNegativeButtonStyle">#style/DialogButtonStyle</item>
<item name="materialAlertDialogBodyTextStyle">#style/AppDialog.Body</item>
<item name="alertDialogStyle">#style/MaterialAlertDialog.App</item>
</style>
<style name="MaterialAlertDialog.App" parent="MaterialAlertDialog.Material3" tools:keep="#style/MaterialAlertDialog_App">
<item name="shapeAppearance">#style/ShapeAppearance.App.MediumComponent</item>
<item name="shapeAppearanceOverlay">#null</item>
</style>
<style name="AppDialog.Body" parent="#style/MaterialAlertDialog.MaterialComponents.Title.Text">
<item name="android:textAppearance">#style/AppDialog.Body.Appearance</item>
</style>
<style name="AppDialog.Body.Appearance" parent="#style/TextAppearance.MaterialComponents.Subtitle1">
<item name="android:textSize">34sp</item>
</style>
I found the answer here, it should be checkedTextViewStyle instead of materialAlertDialogBodyTextStyle. It's a shame that Material 2 documentation is better than Material 3.
I want to change the default textColor of all text in my App. e.g. for all buttons, textViews, EditText's etc. in my App. Before moving to Material3, this was done using:
themes.xml
<style name="MyThemeName" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">#color/black</item>
Now it doesn't work anymore. How do I do it now? The project is a default Android project:
<style name="Theme.MyApplication" parent="Theme.Material3.DayNight.NoActionBar">
<!-- This is not working -->
<item name="android:textColor">#color/black</item>
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_200</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_200</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
I can do it like this, but that is not the answer I'm looking for:
<style name="BaseStyle" parent="android:Widget.Material.Light.Button.Borderless"/>
<style name="Widget.Button.MyCompanyName" parent="BaseStyle">
<item name="android:textColor">#android:color/black</item>
</style>
The above button style I only define the textColor when it differs from the default color that I want.
The text color of the elements will change based on what type of element it is being shown on. for example if you are using the material button by default the button color will be "colorPrimary" and the button text color will be "colorOnPrimary". and similar to this if an element color uses the "colorBackground" its text color will be "colorOnBackground".
in my case i was able to control the text color of all the elements i use by adding a value for the following styles:
<item name="colorOnPrimary">#000000</item>
<item name="colorOnPrimaryContainer">#000000</item>
<item name="colorOnSecondary">#000000</item>
<item name="colorOnSecondaryContainer">#000000</item>
<item name="colorOnBackground">#000000</item>
<item name="colorOnSurface">#000000</item>
<item name="colorOnSurfaceVariant">#000000</item>
<item name="android:textColorPrimary">#000000</item>
<item name="titleTextColor">#000000</item>
you can read more about this in "Typography and iconography colors" section Here
Does the below work? Not sure textViewStyle covers ALL texts. You might need some extra things like <item name="materialButtonStyle"> too.
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:textViewStyle">#style/MyTextView</item>
</style>
<style name="MyTextView" parent="Widget.MaterialComponents.TextView">
<item name="android:textColor">#android:color/black</item>
</style>
I've been trying real hard to theme SearchView. My min API is sdk 21 too, so I should be able to use the new styling options.
Specifically, I want the in-app-bar text field that appears when I click on the search icon to be theme-able. I want to ultimately make the background white, and the text/cursor either blue or black.
Here is my styles.xml. The last theme is the new SearchTheme I'm working on. The actual values don't matter, they're garbage values I threw in just trying to make a change happen.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowBackground">#android:color/white</item>
<item name="android:searchViewStyle">#style/AppTheme.SearchTheme</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.PreferencesTheme" parent="AppTheme">
<item name="android:windowBackground">#android:color/white</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:windowBackground">#android:color/white</item>
<item name="android:searchViewStyle">#style/AppTheme.SearchTheme</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="android:windowBackground">#android:color/white</item>
<item name="android:searchViewStyle">#style/AppTheme.SearchTheme</item>
</style>
<style name="AppTheme.SearchTheme" parent="Theme.AppCompat.Light">
<item name="android:closeIcon">#drawable/contacts5icon</item>
<item name="android:voiceIcon">#drawable/contacts5icon</item>
<item name="android:queryBackground">#android:color/black</item>
<item name="android:windowBackground">#android:color/white</item>
</style>
</resources>
I've assigned the AppTheme.SearchTheme to the other main themes that I'm using in my layout. But nothing I do seems to have any effect. The values don't seem to change.
I haven't really messed with Android theming before, so I'm a bit lost.
This should help you get on the right track, per Chris Banes' walk-through for using material design on pre-lollipop androids. For you, in a nutshell: set item property searchViewStyle under your main style with a Widget.AppCompat.SearchView style extension.
You can use the queryBackground item property for altering the text field's background. Other properties are detailed below.
<style name=”Theme.MyTheme” parent=”Theme.AppCompat”>
<item name=”searchViewStyle”>#style/MySearchViewStyle</item>
</style>
<style name=”MySearchViewStyle” parent=”Widget.AppCompat.SearchView”>
<!-- Background for the search query section (e.g. EditText) -->
<item name="queryBackground">...</item>
<!-- Background for the actions section (e.g. voice, submit) -->
<item name="submitBackground">...</item>
<!-- Close button icon -->
<item name="closeIcon">...</item>
<!-- Search button icon -->
<item name="searchIcon">...</item>
<!-- Go/commit button icon -->
<item name="goIcon">...</item>
<!-- Voice search button icon -->
<item name="voiceIcon">...</item>
<!-- Commit icon shown in the query suggestion row -->
<item name="commitIcon">...</item>
<!-- Layout for query suggestion rows -->
<item name="suggestionRowLayout">...</item>
</style>
more here
So I have this actionBar:
How do I change the style of the MUTE button text so that it isn't bold and is smaller and is of a different color? Adding android:actionMenuTextColor to AppTheme has no effect. Defining android:actionBarStyle also has no effect, like it's being ignored! I've looked at every other answer I can find, nothing works!
These are the styles that produce the actionbar seen above:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat">
<item name="colorPrimary">#color/actionbar_bgr</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">#color/activity_bgr</item>
<item name="android:textColor">#color/activity_text</item>
<item name="android:textSize">#dimen/small_text_size</item>
<item name="android:actionBarStyle">#style/NewActionBar</item>
<item name="android:actionMenuTextColor">#color/test_pink</item>
</style>
<style name="NewActionBar">
<item name="android:background">#color/test_pink</item>
<item name="android:titleTextStyle">#style/NewActionBarTitle</item>
<item name="android:displayOptions">showHome|showTitle</item>
</style>
<style name="NewActionBarTitle">
<item name="android:textSize">#dimen/action_bar_text_size</item>
<item name="android:textColor">#color/test_yellow</item>
</style>
Since you're using the Theme.AppCompat you need to drop the android: in your items name. Also read the answer here and the resource linked in it.
Use android:actionMenuTextAppearance in your main theme. For example, you could set that to #style/NewActionBarTitle:
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionMenuTextAppearance">#style/NewActionBarTitle</item>
</style>
I am trying to change the style of the app but everything is grey instead. What's the problem?
I am using android studio. This project was originally on eclipse. I am not building it using Lollipop on Android Studio
<application
android:name=".MainApplication"
tools:replace="android:icon,android:theme"
android:label="#string/app_name"
android:logo="#drawable/ic_logo"
android:theme="#style/Theme.Materialred" >
styles_materialred.xml:
<resources>
<style name="Theme.Materialred" parent="#style/Theme.AppCompat.Light">
<item name="actionBarItemBackground">#drawable/selectable_background_materialred</item>
<item name="popupMenuStyle">#style/PopupMenu.Materialred</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Materialred</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle.Materialred</item>
<item name="actionDropDownStyle">#style/DropDownNav.Materialred</item>
<item name="actionBarStyle">#style/ActionBar.Solid.Materialred</item>
<item name="actionModeBackground">#drawable/cab_background_top_materialred</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_materialred</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Materialred</item>
</style>
<style name="ActionBar.Solid.Materialred" parent="#style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="background">#drawable/ab_solid_materialred</item>
<item name="backgroundStacked">#drawable/ab_stacked_solid_materialred</item>
<item name="backgroundSplit">#drawable/ab_bottom_solid_materialred</item>
<item name="progressBarStyle">#style/ProgressBar.Materialred</item>
</style>
<style name="ActionBar.Transparent.Materialred" parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="background">#drawable/ab_transparent_materialred</item>
<item name="progressBarStyle">#style/ProgressBar.Materialred</item>
</style>
<style name="PopupMenu.Materialred" parent="#style/Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_materialred</item>
</style>
<style name="DropDownListView.Materialred" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_materialred</item>
</style>
<style name="ActionBarTabStyle.Materialred" parent="#style/Widget.AppCompat.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_materialred</item>
</style>
<style name="DropDownNav.Materialred" parent="#style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:background">#drawable/spinner_background_ab_materialred</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_materialred</item>
<item name="android:dropDownSelector">#drawable/selectable_background_materialred</item>
</style>
<style name="ProgressBar.Materialred" parent="#style/Widget.AppCompat.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_materialred</item>
</style>
<style name="ActionButton.CloseMode.Materialred" parent="#style/Widget.AppCompat.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_materialred</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Materialred.Widget" parent="#style/Theme.AppCompat">
<item name="popupMenuStyle">#style/PopupMenu.Materialred</item>
<item name="dropDownListViewStyle">#style/DropDownListView.Materialred</item>
</style>
Set the color in this way in action bar theme.
<item name="colorPrimary">#color/primaryDef</item>
Read this interesting article of Chris Banes https://chris.banes.me/2014/10/17/appcompat-v21/#migrationfromprevioussetup
I was having this problem and just noticed that there was a separate styles.xml file for Lollipop. It was originally hidden by the default file, but clicking the arrow reveals it. Editing this one works as expected.
You have to use this:
<style name="AppThemeRandom" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<!-- The primary branding color for the app. By default, this is the color applied to the
action bar background. -->
<item name="colorPrimary">#color/md_indigo_500</item>
<!-- Dark variant of the primary branding color. By default, this is the color applied to
the status bar (via statusBarColor) and navigation bar (via navigationBarColor). -->
<item name="colorPrimaryDark">#color/md_indigo_700</item>
<!-- Bright complement to the primary branding color. By default, this is the color applied
to framework controls (via colorControlActivated). -->
<item name="colorAccent">#color/md_pink_A200</item>
<!-- The color applied to framework controls in their normal state. -->
<item name="colorControlNormal">#color/md_amber_500</item>
<!-- The color applied to framework controls in their activated (ex. checked) state. -->
<item name="colorControlActivated">#color/md_green_500</item>
<!-- The color applied to framework control highlights (ex. ripples, list selectors). -->
<item name="colorControlHighlight">#color/md_teal_500</item>
<!-- The color applied to framework buttons in their normal state. -->
<item name="colorButtonNormal">#color/md_red_500</item>
<!-- The color applied to framework switch thumbs in their normal state. -->
<item name="colorSwitchThumbNormal">#color/md_black_1000_50</item>
<!-- Inactive track color(75% transparency) -->
<item name="android:colorForeground">#color/md_black_1000_75</item>
</style>
Obviously, choose your colors, it is a random theme to check all colors in status bar, toolbar, widgets like checkbox, etc.