4

I know that there are varios questions about customized theme for actionbar-sherlock. I also try the accepted answer but no thing change. Here is my theme:

<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 my activity declaration:

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

My applciation 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 new background to the actionbar sherlock as well as new text font for the title but I can't. Please tell me where is my mistakes to make this works.

UPDATE: Java source I user overlay actionbar 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

1 に答える 1

3

oncreate()このコードをアクティビティのメソッドに追加します

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

これを解決します。

于 2013-01-10T10:56:19.720 に答える