Configure theme in action bar-sherlock does not work

I know there are varios questions about a custom theme for actionbar-sherlock. I also accept the accepted answer, but nothing changes. Here is my topic:

<resources> <style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar"> <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item> <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item> </style> <style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse"> <item name="background">@drawable/actionbar_background</item> <item name="android:background">@drawable/actionbar_background</item> <item name="backgroundSplit">@drawable/actionbar_background</item> <item name="android:backgroundSplit">@drawable/actionbar_background</item> </style> </resources> 

And here is the announcement of my activity:

  <activity android:name="com.ihnel.tinyapp.xskt.Home" android:theme="@style/Theme.Styled" android:configChanges="orientation|keyboard" /> 

My applications will run on Android 2.1+, so I declare the Android version as:

  <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17" /> 

I want to set a new background in sherlock for the action bar, as well as a new text font for the title, but I cannot. Please tell me where are my mistakes so that it works.

UPDATE: Java source I custom action bar style:

  requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); 

Here is the code to add menu items:

 public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) { menu.add("Search") .setIcon(R.drawable.ic_action_search) .setActionView(R.layout.search_edittext) .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); SubMenu sub = menu.addSubMenu("Theme"); sub.add(0, R.style.Theme_Sherlock, 0, "Default"); sub.add(0, R.style.Theme_Sherlock_Light, 0, "Light"); sub.add(0, R.style.Theme_Sherlock_Light_DarkActionBar, 0, "Light (Dark Action Bar)"); sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); return true; }; 

Thanks.

+4
source share
1 answer

Add this code to the oncreate() method in your activity

 getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_background)); 

This will solve it.

+3
source

All Articles