2

如何更改操作欄(actionbarsherlock)的顏色?如何更改操作欄的顏色(actionbarsherlock)

我已經嘗試了下面的代碼,但沒有運氣。

<style name="MyTheme.ActionBarStyle" parent="Widget.Sherlock.ActionBar"> 
    <item name="background">#ffffffff</item> 
</style> 

<style name="Theme.SherlockCustom" parent="@style/Theme.Sherlock.Light"> 
    <item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item> 
</style> 

+還有一件事,我添加像下面的子菜單。這個按鈕的背景顏色也是白色的(因爲Sherlock主題)。我可以改變這些顏色嗎?

SubMenu sub = menu.add("abcd"); 
    sub.add(0, 1, 0, "Default"); 
    sub.add(0, 2, 0, "Light"); 
    sub.add(0, 3, 0, "Light (Dark Action Bar)"); 
    sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); 

回答

0

使用這種樣式:

<style name="MyTheme.ActionBarStyle" parent="Widget.Sherlock.ActionBar"> 
     <item name="background">#ffffffff</item> 
     <item name="android:background">#ffffffff</item> 
</style> 

我假設你的HC或以上的設備上測試您的應用程序,因爲你沒有指定本地動作條的背景下,它沒有工作。改變它上面的風格,它應該工作。

1

你第一次發佈的內容幾乎完全正確,這是你需要添加來更改ActionBar顏色的主題。與背景顏色屬性:您還應該添加了android

<style name="MyTheme.ActionBarStyle" parent="Widget.Sherlock.ActionBar"> 
    <item name="background">#ffffffff</item> 
    <item name="android:background">#ffffffff</item> 
</style> 

<style name="Theme.SherlockCustom" parent="@style/Theme.Sherlock.Light"> 
    <item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item> 
</style> 

但是,你需要確保你,要麼適用於你的整個應用程序,或者只是要在顯示它的活動你。可以使用android:theme屬性在AndroidManifest.xml中的應用程序標籤或activity標籤中執行此操作。

<application 
    android:name="com.your.package.name" 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    android:theme="@style/Theme.SherlockCustom" > 
2

我認爲你應該使用@style/Widget.Sherlock.Light.ActionBar.Solid@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse作爲父母的ActionBarStyle和兩個屬性backgroundandroid:background。例如:

<style name="MyTheme.ActionBarStyle" parent="@style/Widget.Sherlock.Light.ActionBar.Solid"> 
    <item name="background">#ffffff</item> 
    <item name="android:background">#ffffff</item> 
</style> 

<style name="Theme.SherlockCustom" parent="@style/Theme.Sherlock.Light"> 
    <item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item> 
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item> 
</style> 

ActionBar style generator可能會幫助您設計子菜單樣式。

6

當談到造型actionBar時,最好的辦法是使用非常流行的Action Bar Style Generator這是一個web應用程序,它可以讓你預覽ActionBar的外觀,並讓你下載所有必要的資源只需將其添加到您的產品:9個插頁,狀態可繪製和.xmls。

如果你不確定如何使用它,這裏有一個快速的guide

使用這是確保操作欄看起來不錯的最佳選擇,而不會浪費大部分時間,而這些時間可能會花在有價值的Java代碼上。

+0

最好的解決辦法+1 – 2013-07-23 16:05:35

-1

創建自定義操作杆,那麼你會做出行動吧福爾摩斯的顏色變化.....

+0

創建自定義ActionSherlock吧...... HTTP:// hariandroid.wordpress.com/2013/11/20/how-to-create-custom-sherlock-bar-in-android-programmatically/ – harikrishnan 2014-02-13 05:43:24

2
I just used below Code 

getSupportActionBar().setBackgroundDrawable(new 
    ColorDrawable(Color.parseColor("#00853c"))); 

it changed the bg color. Hope, it helps.