I style a theme using Android asset studio. and i set my app theme in my manifest file.
here my all layouts background color is white i want to change that into some other color. i need to mention my all layout background color in my Style.xml...
how we can do that...
<style name="Theme.Jwellers" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#drawable/selectable_background</item>
<item name="android:popupMenuStyle">#style/PopupMenu.</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="android:actionDropDownStyle">#style/DropDownNav</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid</item>
<item name="android:actionModeBackground">#drawable/cab_background_top</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.</item>
<!-- Light.DarkActionBar specific -->
<item name="android:actionBarWidgetTheme">#style/Theme.mytheme.Widget</item>
</style>
If you have the color saved as a drawable just add
<item name="android:background">#drawable/drawableNameOfColor</item>
That should make the background color whatever you have assigned to the drawable drawableNameOfColor
Related
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>
In the custom style, the background color is changing but only the font color isn't changing.
<style name="CustomChipStyle" parent="Widget.MaterialComponents.Chip.Filter">
<item name="chipBackgroundColor" >#color/chips_bg_color</item>
<item name="android:textColorHint">#color/chips_text_color</item>
<item name="chipIconTint">#color/tomato_red</item>
<item name="rippleColor">#color/white</item>
</style>
<style name="CustomChipStyle" parent="Widget.MaterialComponents.Chip.Filter">
<item name="chipBackgroundColor" >#color/chips_bg_color</item>
<item name="android:textColor">#color/chips_text_color</item>
<item name="chipIconTint">#color/tomato_red</item>
<item name="rippleColor">#color/white</item>
You need to use android:textColor for changing your font color.
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>
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.
i generated custom theme for my app on:
http://jgilfelt.github.io/android-actionbarstylegenerator/
And now i would like to add custom color for background of all activities ale fragments in the app.
I tried to do by this way, but it colors also backgroud of text views and images too (which i don't need).
How can i do it to avoid set custom background of the each activity or fragment layout ?
Thanks for any advice
<style name="Theme.Custom" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarItemBackground">#drawable/selectable_background_custom</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Custom</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Custom</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.Custom</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Custom</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.Custom</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_custom</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_custom</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Custom</item>
<item name="android:background">#color/custom_white</item>
<!-- Light.DarkActionBar specific -->
<item name="android:actionBarWidgetTheme">#style/Theme.Custom.Widget</item>
</style>
You can try adding windowBackground item to your theme, this should color all your activities' backgrounds.
<resources>
<style name="MyTheme" parent="#android:style/Theme.Light">
<item name="android:windowBackground">#color/background</item>
</style>
</resources>