2014-02-25 44 views
2

我正嘗試在應用程序中更改操作欄的顏色。我找到了this answer這表明了一種方法。所以,我創建了一個themes.xml文件res/values文件夾下有以下幾點:如何使用actionbarsherlock更改操作欄的顏色

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="Theme.MyTheme" parent="Theme.Sherlock.ForceOverFlow"> 
     <item name="actionBarStyle">@style/Widget.MyTheme.ActionBar</item> 
     <item name="android:actionBarStyle">@style/Widget.MyTheme.ActionBar</item> 
    </style> 

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

不過,我得到在上面的代碼中的錯誤:

的項目

錯誤檢索父:沒有資源發現匹配 名稱爲'Theme.Sherlock.ForceOverFlow'。

在我的build.gradle

我有以下幾點:

compile 'com.actionbarsherlock:actionbarsherlock:[email protected]' 

我使用AndroidStudio和搖籃

+0

如果你正在使用Eclipse,我有時編輯我的風格的時候會有奇怪解析錯誤。 xml文件。您是否嘗試打開「問題」窗口,刪除錯誤消息並嘗試重建項目? - 另外,如果您使用的是4.2.0或更高版本,那麼顯然它已被刪除:http://stackoverflow.com/a/13180285/1426565 – Guardanis

回答

1

ActionBarSherlock 4.4版不包括ForceOverflow主題,它在4.2被刪除。您將需要使用較舊版本的ABS以ForceOverflow作爲主題。

由於每Change Log

修復:刪除.ForceOverflow主題。這些永遠不應該包括在內 。

如果你實際上並不需要的ForceOverflow,你可以使用Theme.Sherlock,見the official page詳細信息:

<style name="Theme.MyTheme" parent="Theme.Sherlock"> 
    <item name="actionBarStyle">@style/Widget.MyTheme.ActionBar</item> 
    <item name="android:actionBarStyle">@style/Widget.MyTheme.ActionBar</item> 
</style> 
+0

嗯我不知道什麼是4.4後改變操作欄的顏色的選項,然後。 – Anthony

+0

編輯我的答案。這對你有用嗎? – 2Dee

+0

獲取代碼編譯並運行,但是,操作欄的顏色仍然相同。我甚至在我的所有活動的「onCreate」中添加了'setTheme(R.style.Theme_MyTheme)'。 – Anthony