1

I'm trying to customize the action bar. I've done it before too, but I'm unable to do it now. Not sure where I'm going wrong.

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/actionbar_gradient</item>
</style>

This is the drawable that I'm adding

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="270"
        android:startColor="#d6ece542"
        android:endColor="#fffffdf4"
        />
</shape>

I've also added this inside <application> tag in my manifest:

android:theme="@style/AppTheme"

But every time I'm just getting the same action-bar (the default of the theme). Can someone tell what's wrong?

Also FYI, my minSdk version=18, and target version=21

ScreenSeer
  • 549
  • 2
  • 9
  • 22
  • make sure you are adding `android:theme="@style/AppTheme"` to `` tag of manifest file. – Apurva Mar 04 '15 at 20:23
  • @Apurva: I want to apply the theme over the entire application hence I've already added that line inside the tag. I've done this before on other projects too, not sure what is happening differently here – ScreenSeer Mar 05 '15 at 06:38

2 Answers2

3

It looks like you're trying to apply a Holo action bar theme to a Material AppCompat theme.

One solution is to apply the gradient as the colorPrimary:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@drawable/actionbar_gradient</item>
</style>

More customization attributes: https://developer.android.com/training/material/theme.html#StatusBar

Another solution would be to just switch to the Holo theme:

  1. Change your activity to extends Activity
  2. Change your parent theme to @android:style/Theme.Holo.Light.DarkActionBar
tachyonflux
  • 20,103
  • 7
  • 48
  • 67
  • I didn't understand how you got that assumption. But the fact is that I can't change it to what you said because that needs minimum to be API level 21. Mine is 18. So I'm not using the material theme in the first place. – ScreenSeer Mar 05 '15 at 06:46
  • You are using app compat for v21, which is material design. What exactly requires v21? Your comment is too vague for me to respond to. – tachyonflux Mar 05 '15 at 07:46
  • If you're referring to the link, that is not using the appcompat library. If you use the appcompat library, the attributes are not `android:` namespaced. I just wanted to include that image. – tachyonflux Mar 05 '15 at 07:50
  • My minSdkVersion 18 and targetSdkVersion 21, so I was getting an error that my minimum version needs to be 21. But there was an override option, which created a styles.xml (v21) file. After I applied my theme to that the theme was visible in cardview (when I see all my stacked apps), but not on viewing the app itself – ScreenSeer Mar 05 '15 at 08:27
  • I figured out what the problem was. My gradient was using transparent colours, so when I was trying your method I was encountering errors. Could you please edit this detail in your answer? Thank you – ScreenSeer Mar 05 '15 at 08:39
  • I still don't follow. The first solution is good as far back as v7. The second is good back to v11~v14 depending on your action bar theme parent. If you have an edit, feel free to submit it. – tachyonflux Mar 05 '15 at 19:22
0

You probably need to add android:type="linear" to that gradient definition

<gradient
    android:angle="270"
    android:startColor="#d6ece542"
    android:endColor="#fffffdf4"
    android:type="linear"
    />
frogatto
  • 28,539
  • 11
  • 83
  • 129