I'm trying to set up my styles to make all buttons a particular color combination, specifically blue with white text. Here's my main styles.xml:
<resources>
<style name="CustomTheme" parent="MaterialDrawerTheme.Light.DarkToolbar">
<!-- various items -->
<item name="android:buttonStyle">#style/ButtonStyle</item>
</style>
<!-- a couple of other styles -->
<style name="ButtonStyle" parent="android:style/Widget.Button">
<item name="android:textSize">19sp</item>
<item name="android:textColor">#color/primaryTextContrast</item>
<item name="android:background">#color/primary</item>
</style>
</resources>
And in the manifest:
<application
android:name=".CustomApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/application_name"
android:theme="#style/CustomTheme">
color/primary is dark blue, and color/primaryTextContrast is white. On Lollipop, the button looks perfect. On a 4.1 device, it's light gray with black text. Every resource I've found for doing this looks exactly like what I'm doing so I don't know what I'm missing here.
I'm having a similar issue with controlling text size in the base style definition as well.
Update: here are the colors.
<resources>
<color name="primary">#3F51B5</color>
<color name="dark">#303F9F</color>
<color name="accent">#FFCA28</color>
<color name="background">#android:color/white</color>
<!-- Color for text displayed on top of the primary or dark color -->
<color name="primaryTextContrast">#android:color/white</color>
<!-- Color for text displayed on the background color (which I think will always be white) -->
<color name="basicText">#color/primary</color>
<!-- Color for text displayed on the accent color -->
<color name="accentText">#303F9F</color>
</resources>
Here's v19/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="FullscreenTheme" parent="MaterialDrawerTheme.Light.DarkToolbar.TranslucentStatus">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
Here's v21:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="CustomTheme">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">#android:transition/move</item>
<item name="android:windowSharedElementExitTransition">#android:transition/move</item>
</style>
</resources>
I don't think either of these is what's making it work properly on 5.1.
Using AppCompat 22.1.+ (22.2.0 should work too), I defined a Style like this:
<style name="MyApp.Button.Red" parent="Base.Widget.AppCompat.Button">
<item name="colorButtonNormal">#color/primary</item>
<item name="android:colorButtonNormal">#color/primary</item>
<item name="android:textColor">#android:color/white</item>
</style>
and then applied the theme in a button using the native theme attribute from android namespace, as said in this awesome post from Chris Banes.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_button"
android:theme="#style/MyApp.Button.Red" />
I tried adding buttonStyle without the android: prefix and it solved the problem. Yeah, weird.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="buttonStyle">#style/ButtonStyle</item>
<item name="android:buttonStyle">#style/ButtonStyle</item>
</style>
gradle:compile 'com.android.support:appcompat-v7:22.2.0'
For theme to work properly in android lollipop, you need to extend
ActionBarActivityinstead of Activity.
By doing this change,your theme setting should work properly.
This is general for other people that for lower version of android,you should not use android: tag in item-name definition
`
Related
Currently all my text and hint colour by default is all white, although I do ok when I'm able to change them in xml file, but certain stuff like TextInputLayout text counter doesn't allow colour change
below are my colors.xml
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#5CCDCC</color>
below are 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="colorPrimaryDark">#color/GreenishBlue</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowLightStatusBar">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
AndroidManifest was modified like this:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme">
And the file res/values/styles.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textColor">#000</item> //black color for text
<item name="android:textColorHint">#939393</item> //Gray color for hint
</style>
</resources>
Adding below code to your existing AppTheme will change default text color in controls where text color is not set inline in xml, using different style or dynamically.
<item name="android:textColor">#000000</item>
<item name="android:textColorHint">#666666</item>
I'm trying to change the colors of my StatusBar, when I try to alterate the colorPrimaryDark (first bar, where stays batery, tima, date, etc...) the color do not change.
I've created a xml with the values of the colors that I use
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name = "primary">#162d50</color>
<color name = "primary_dark">#010101</color>
<color name = "textprimary">#FFFFFF</color>
</resources>
And my styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<item name="android:textColorPrimary">#color/textprimary</item>
</style>
</resources>
In other words, I can change colors of my background, titlebar, text, but when I try to change colorPrimaryDark, no matter what the value entered the color never change, could someone help me please?
Change your theme to this.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
Remove android tag and try it again.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="textColorPrimary">#color/textprimary</item>
</style>
</resources>
There are various ways to change color of status bar. Below is my solution.
Edit your style.xml as below. You can directly add android:statusBarColor tag to your xml.
<!-- 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:statusBarColor">#d9591b</item>
</style>
Note -: android:statusBarColor is available in minsdk version 21. It will not work below api level 21. You need to modify your gradle file. Change minSdkVersion to 21.
Edit Your Style.Xml and add this within the resources tags:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colortoolbar</item>
<item name="colorPrimaryDark">#color/colortoolbar</item>
<item name="colorAccent">#color/colortoolbar</item>
</style>
where colortoolbar is already defined in my colors.xml. You can define your own color.
I've used inbuilt theme Theme.AppCompat.NoActionBar for my app. But it gives complete black background. I want to change this black background to gray one. So I tried to customize my theme as following:
Here is my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="MyTheme"> // Using Customized theme.
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
//Customize the Theme.
<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:backgroundDimAmount">0.8</item>
</style>
Here I want to lighten my background color so I'm using android:backgroundDimAmount but it is not working.
I've also used following:
<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:background">#707070</item>
</style>
This changes the background color, but gives me weird results as following screen shot:
Where as My actual activity looks like following screen shot:
So my question how can I lighten or possibly change the background color?
you want this
<item name="android:background">#color/<mycolor></item>
<item name="android:windowBackground">#color/<mycolor></item>
<item name="android:colorBackground">#color/<mycolor></item>
remember to change it in all styles xmls
you should use style as this in style.xml.....
<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:background">#color/gray</item>
<item name="android:windowBackground">#color/gray</item>
<item name="android:colorBackground">#color/gray</item>
</style>
</resources>
and in colors.xml make this.....
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="gray">#707070</color><!--this your color-->
</resources>
the final out put
Replace android:background to android:windowBackground.
Also change the hardcoded color (e.g #707070) to color reference (e.g #color/myYellowBackgroundColor) .
When using android:windowBackground you tell android to affect background of child's view only inside the main activity on the screen.
use this in your styles.xml file
<item name="android:statusBarColor">#color/yourcolor</item>
remember to add your color in color.xml file. don't hardcode your color.
My ActionMode menu is showing up as plain white and I don't know why.
I have an ActionMode menu.xml which simply has a delete option:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_delete"
android:title="Delete"
android:icon="#android:drawable/ic_menu_delete"/>
</menu>
and I have a theme applied to my whole app, defined in styles.xml:
<resources>
<!-- Base application theme -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/paletteLightBlue3</item>
<item name="colorPrimaryDark">#color/dark_grey</item>
<item name="colorAccent">#color/paletteLightBlue</item>
<item name="android:actionModeStyle">#style/aModeBg</item>
</style>
<style name="aModeBg" parent="#style/Widget.AppCompat.ActionMode">
<item name="android:actionModeBackground">#color/dark_red</item>
</style>
</resources>
As you can see, I've tried setting the actionModeBackground property to dark red, but it still just shows up as white. Can anyone help? Thanks.
OK so I solved this by simply doing this:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/paletteLightBlue3</item>
<item name="colorPrimaryDark">#color/dark_grey</item>
<item name="colorAccent">#color/paletteLightBlue</item>
<item name="android:actionModeBackground">#color/dark_red</item>
</style>
I just put set the actionModeBackground in my AppTheme, instead of a separate style. Simple.
The title says it all: how can I style my PreferenceFragmentCompat. My v14/style.xml is
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:editTextStyle">#style/Widget.EditText.White</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay</item>
</style>
<style name="Widget.EditText.White" parent="#android:style/Widget.EditText">
<item name="android:textColor">#ffffffff</item>
</style>
</resources>
The base theme has a black background - the preferences screen is then unreadable as I have black text on that black background.
I've tried many things but I cannot change the text colour.
What I've had to do is to set the fragment container background colour to white whilst the settings fragment is active. An ugly hack and not what I want to have to do.
To answer my own question: my v14/style.xml is now
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:editTextStyle">#style/Widget.EditText.White</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
</style>
<style name="Widget.EditText.White" parent="#android:style/Widget.EditText">
<item name="android:textColor">#ffffffff</item>
</style>
<style name="PreferenceThemeOverlay.v14">
<item name="android:background">#color/settings_background</item>
<item name="android:textColor">#color/settings_text_colour</item>
<item name="android:textColorSecondary">#color/settings_text_colour_secondary</item>
</style>
</resources>
My problem is now to style a ListPreference.
Why is this so hard? If there is any documentation relating to styling preferences, it is well hidden. Grrrrrr!
Take a look at README for github project
Gericop/Android-Support-Preference-V7-Fix