2014-07-11 31 views
8

我使用Theme.AppCompat爲我的應用程序得到黑暗的樣子。一切看起來不錯,除了使用這個主題的動作欄看起來很古老,即它有一個明亮的藍色底部分隔線。黑暗行動酒吧與Theme.AppCompat

我想讓動作欄看起來像是在Theme.AppCompat.Light.DarkActionBar

看着themes.xml,我發現:

<style name="Theme.AppCompat.Light.DarkActionBar" 
     parent="Theme.Base.AppCompat.Light.DarkActionBar"> 
    <item name="windowActionBar">true</item> 
</style> 


<style name="Theme.Base.AppCompat.Light.DarkActionBar" parent="Theme.Base.AppCompat.Light"> 
    <item name="actionBarDivider">@drawable/appcompat_divider_dark</item> 
</style> 

所以我創造我自己的風格,如下:

<style name="myTheme" parent="@style/Theme.AppCompat"> 
    <item name="actionBarDivider">@drawable/appcompat_divider_dark</item> 
</style> 

,但我得到的編譯錯誤:

No resource found that matches the given name (at 'actionBarDivider' with value 
'@drawable/appcompat_divider_dark') 

爲什麼能我是否使用框架使用的相同drawable?

+0

你試過''? –

+0

@ FrankN.Stein是的,我有。它沒有任何區別。 Eclipse向我展示的錯誤是在可繪製的資源引用中,而不是在屬性名稱中,有或沒有'android:'。 – faizal

+0

'@ drawable/appcompat_divider_dark'表示您在'/ res/drawable'文件夾中有一個名爲'appcompat_divider_dark.png'(或.9.png或.jpg)的資源。是這樣嗎? –

回答

1

藍線是用於操作欄的背景圖像的一部分。例如,您可以在以下位置找到它:sdk/platforms/android-19/data/res/drawable-xxhdpi/ab_transparent_dark_holo.9.png

訣竅是通過繼承Widget.AppCompat.ActionBar來創建您自己的Widget風格,並將背景屬性設置爲您所需的png,它不具有藍色線條。我使用支持庫的現有@drawable/abc_ab_bottom_transparent_dark_holo。您可以在文件夾sdk/extras/android/support/v7/appcompat/res/drawable-hdpi/中找到它。

因此,在styles.xml文件中創建下面的元素。

<style name="myActionBar" parent="@style/Widget.AppCompat.ActionBar"> 
     <item name="android:background">@drawable/abc_ab_bottom_transparent_dark_holo</item> 
</style> 

然後包括你的主題這個新創建的風格(已經存在於styles.xml文件):

<style name="AppBaseTheme" parent="@style/Theme.AppCompat"> 
     <item name="android:actionBarStyle">@style/myActionBar</item> 
</style> 

爲了使老年API的這種變化,使所有3文件夾相同的變化 - values-v14,values-v12values。 需要注意的一點是,「android:」名稱空間不應用於values-v12values文件夾中的名稱屬性。