Question

I am using actionbarsherlock. with my custom theme

In the values/styles.xml i have entered this.

<style name="Mytheme" parent="@style/Theme.Sherlock.Light">
    <item name="android:background">@drawable/actionbar_bg</item>
</style>

actionbar_bg

<?xml version="1.0" encoding="utf-8"?>
<gradient xmlns:android="http://schemas.android.com/apk/res/android"
    android:type="linear"
    android:centerX="8%" 
    android:startColor="#969696" 
    android:centerColor="#FFFFFF" 
    android:endColor="#FFFFFFFF" 
    android:angle="270"
/>

Manifest

<activity
        android:name="com.example.myapp.Secondactivity"
        android:label="@string/title_activity_second"
         android:theme="@style/Mytheme">
 </activity>

Logcat Error Unable to start activity, android.view.InflateException: Binary XML file line #21: Error inflating class

The app works fine when I remove the android:theme="@style/Mytheme" Line

UPDATE: I changed android:background to just "background", and the app doesn't force close now. but the gradient is not applied. all I could see is a grey actionbar.

UPDATE #2

modified styles.xml as follows

<style name="Mytheme" parent="@style/Theme.Sherlock.Light">
<item name="actionBarStyle">@style/MyActionBarTheme</item>
</style>

<style name="MyActionBarTheme" parent="Widget.Sherlock.ActionBar">
<item name="background">@drawable/actionbar_bg</item>
<item name="android:background">@drawable/actionbar_bg</item>
</style>

In Manifest I call the theme as android:theme="@style/MyActionBarTheme" .

as you can see in the image the gradient is spread across the window and not just the actionbar

enter image description here

Was it helpful?

Solution

add this actionbar_bg.xml

enter image description here

Drawable dr = getResources().getDrawable(R.drawable.actionbar_bg);
getActionBar().setBackgroundDrawable(dr);

actionbar_bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <gradient
        android:angle="270"
        android:centerColor="#FFFFFF"
        android:centerX="8%"
        android:endColor="#FFFFFFFF"
        android:startColor="#969696"
        android:type="linear" />

</shape>

OTHER TIPS

Try without android in your xml attribute name:

<style name="Mytheme" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/Widget.MyActionBarTheme</item>
    <item name="android:actionBarStyle">@style/Widget.MyActionBarTheme</item>
</style>

<style name="Widget.MyActionBarTheme" parent="Widget.Sherlock.ActionBar">
    <item name="background">@drawable/actionbar_bg</item>
</style>

The one with android would be for native ActionBar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top