Reputation: 537
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
Upvotes: 3
Views: 501
Reputation: 4119
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.
Upvotes: 1
Reputation: 18978
add this actionbar_bg.xml
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>
Upvotes: 1