it feels like, I have searched the whole internet for this... I'm currently writing an app, in which the statusbar color should be red in v21 (Lollipop) and above. The current code from values-v21/styles.xml is
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<item name="android:colorPrimary">#color/primaryColor</item>
<item name="android:colorPrimaryDark">#color/primaryColorDark</item>
<item name="android:colorAccent">#color/primaryColor</item>
<item name="android:statusBarColor">#color/primaryColorDark</item>
<item name="android:navigationBarColor">#color/primaryColorDark</item>
<item name="android:windowBackground">#color/darkWhite</item>
</style>
</resources>
This code does not work. The strange thing is, it only doesn't work in v21, in v22 (Android 5.1) it is shown as fully working. Do anyone know how I get it working on v21?
(Sry for bad English)
It works for me but I use
item name="colorPrimaryDark"
Without 'android' before the attributes.
Got it, it doesn't work, if v21 isn't the targetSdk in the Manifest.
Related
i am trying to change the style of the action bar in android.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="GoetheTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/GoetheActionBar</item>
</style>
<style name="GoetheActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/base_color_dark</item>
</style>
So yeah, thats what I got. Now I have put the application theme in the android manifest to the created one (GoetheTheme). But the ActionBar does not change. If I set it to #GoetheActionBar, it does. Why does GoetheTheme style don't take the GoetheActionBar style?
Can please someone explain me the style system? I really dont get it.
Thanks in advance
Sorry, my very bad. I found out, I have to use a different parameter as parent ^^
I took a Light theme based one not android specific.
Correct:
<style name="GoetheActionBar"parent="#android:style/Theme.WithActionBar">
<item name="colorPrimary">#color/base_color_dark</item>
</style>
<style name="GoetheTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/GoetheActionBar</item>
</style>
I understand that to correctly use some of the Material theme design patterns for pre API-21 devices, I'll have to include two style folders.
The theme is applied correctly on my Nexus 5 (lolipop) device, but when I run my application on a pre API-21 device (I'm using my Samsung Galaxy Note, API-16), I'm getting a blank, black screen. The application works, as I can interact with the activity (press buttons, use the keyboard, etc), but I can't see anything.
Here is my res/values-v21/themes.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="AppTheme">
<item name="colorPrimary">#color/green</item>
<item name="colorPrimaryDark">#color/darkgreen</item>
</style>
</resources>
and here is my res/values/themes.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
</style>
</resources>
and I've included this line inside my manifest file under <application>:
android:theme="#style/Theme.MyTheme"
Am I not supposed to use the AppCompat theme for pre-lolipop devices? I'm using the v7 support library.
Any help is appreciated.
Change your res/values/themes.xml in:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/green</item>
<item name="colorPrimaryDark">#color/darkgreen</item>
</style>
Then remove the same theme (name="Theme.MyTheme") from res/values-v21/themes.xml
I am trying to get all of my activities to have a custom theme style that should look like this:
This theme works on many devices, including the Nexus 7, the Samsung Galaxy S4, and the Samsung Droid Charge (running Gingerbread). However, on other devices, such as HP Slate 7 and Motorola Droid RAZR, it ends up looking like this:
I have the following in my AndroidManifest.xml's application tag:
android:theme="#style/AppTheme"
The theme is as follows in res/values/styles.xml:
<style name="AppBaseTheme" parent="#android:style/Theme.Light.NoTitleBar">
</style>
<style name="AppTheme" parent="#style/AppBaseTheme">
<item name="android:windowBackground">#color/background</item>
</style>
I have also added a styles.xml under res/values-v11. Here is the applicable style from there:
<style name="AppBaseTheme" parent="#android:style/Theme.Holo.Light.NoActionBar">
</style>
Finally, this appears in styles.xml under res/values-v14:
<style name="AppBaseTheme" parent="#android:style/Theme.DeviceDefault.Light">
</style>
I have tried to define the theme for each activity and to manually use the setTheme() function in onCreate(), but nothing has worked. I have also tried to manually set a background in every Activity, and this did not work either. What can I do to fix my problem?
EDIT: What's interesting is setting android:background in the styles makes it work, but then elements that should not have backgrounds receive that background color as well.
The key to solving the problem was changing android:windowBackground in the theme to the following:
<item name="android:windowBackground">#drawable/default_background</item>
Notice that I am no longer using #color, but simply a #drawable, the xml for which is below:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#color/background"/>
</shape>
It seems that some devices do not support accepting a color for this element.
I found that the latest version of Android Studio expect that the parent for the style needs to be Theme.AppCompat. Also, it is good style to create a colors.xml file in the values directory (with named color elements between the resource tags). Put your RGB values as values to the named color elements. Reference them in your styles with #color/.
<!--colors.xml in values folder-->
<resources>
<color name="color1">#ffb62a23</color>
<color name="color2">#ffedeba6</color>
<color name="color3">#00ff00</color>
</resources>
<!--style tags -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowBackground">#color/color2</item>
<item name="android:textColorPrimary">#color/color1</item>
<item name="android:textColorSecondary">#color/color2</item>
<item name="android:textColorTertiary">#color/color3</item>
</style>
I am operating with the compatibility library v7.
I am just trying to set the color of my actionbar (for Android 2.1 and above - though I run Android 4.4.2) to a solid color.
However the color does not change. It remains the same.
I have also tried creating a solid drawable with the color but that also does not change.
Finally I tested if I could change the backgroudn of my layout and I could - it must be something about the actionbar background which I'm not getting.
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#0000ff</item>
</style>
</resources>
This seems to work for me. Try to use a resource instead of a raw value.
<style name="app_theme" parent="#android:style/Theme.Holo">
<item name="android:actionBarStyle">#style/app_action_bar</item>
</style>
<style name="app_action_bar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#color/google_lightest_gray</item>
<item name="android:icon">#android:color/transparent</item>
<item name="android:windowActionBarOverlay">false</item>
</style>
use getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#808080"))); in Activity extends SherlockActivity or the color as your wish :)
You can use:
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.colorname));
use the following code getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg_color.xml));
actionbar_bg_color.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#color/actionbar_bg"/> <!-- set desired #0000ff color in color.xml
you can use here solid color as well as gradient -->
</shape>
hope this help you
I solved it by:
Properly installing the support-v7-appcompat library.My mistake.
Shifting the styling to the res/values/styles.xml files for each version, i.e. one for backwards compatibility and one for values-v11.
I don't know why I couldnt get the result I wanted within themes.xml.
If anyone has an answer I'd be grateful
I am using the ActionBarSherlock and almost everything seems to work fine.
But I want the title text color in white. When using the Sherlock-Actionbar it works fine but not with the original ActionBar in Android 4
In an act of desperation I tried this:
<style name="Widget.AppTheme.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
<item name="titleTextStyle">#style/TextAppearance.AppTheme.Widget.ActionBar.Title</item>
<item name="android:gravity">center</item>
<item name="android:background">#color/white</item>
<item name="android:textColor">#color/white</item>
</style>
and found that the background changed as told to white. So this is obviously the right place to change. But still changing the textColor to white doesn't work for me.
I'm using this as my Theme:
<style name="AppTheme" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/Widget.AppTheme.ActionBar</item>
<item name="actionBarStyle">#style/Widget.AppTheme.ActionBar</item>
<item name="textColorPrimary">#color/white</item>
<item name="android:textColor">#color/white</item>
...
</style>
So any idea what could be the problem? Why is it working with the background but not with the textColor?
Thanks,
Tobias
--- EDIT FROM HERE ---
I just found out that if I use my theme programmaticall like
setTheme(R.style.Widget_AppTheme_ActionBar);
It works. But if I rely on the settings I have in my Manifest it doesn't.
<application ... android:theme="#style/AppTheme" >
but
<application ... android:theme="#style/Widget_AppTheme_ActionBar" >
would do fine - even though the other styles from the AppTheme wouldn't be set.
So it looks like using a theme that defines an own ActionBarStyle doesn't work.
Has anyone any idea?
Okay, sorry for answering my own question. I eventually realized my problem.
Of cause I have to use these two arguments
<item name="titleTextStyle">#style/TextAppearance.AppTheme.Widget.ActionBar.Title</item>
<item name="android:titleTextStyle">#style/TextAppearance.AppTheme.Widget.ActionBar.Title</item>
Since the first one is working for Android 2.x with the ActionBarSherlock and the second one is doing the same for the native Action Bar.
I hope this helps someone who has the same trouble as I had.