2013-08-21 81 views
7

我想定製以下this參考我的動作條的標籤指示,但我得到的錯誤:沒有資源發現@風格/ Widget.Holo.ActionBar.TabView

Error retrieving parent for item: No resource found that matches the given name '@style/Widget.Holo.ActionBar.TabView'.  

最低SDK設置到14,目標SDK = 18。任何想法?

編輯:

我已經有下列樣式其工作:

 <style name="sMain" parent="@android:style/Theme.Holo"> 
    <item name="android:icon">@android:color/transparent</item> 
    <item name="android:actionBarStyle">@style/MyActionBar</item> 
    <item name="android:actionBarDivider">@null</item> 
</style> 

<style name="MyActionBar" parent="android:Widget.Holo.ActionBar"> 
    <item name="android:actionBarDivider">@null</item> 

</style> 
+0

你還在嗎? –

+0

哦對不起,忘了接受。您的建議有效,謝謝 – Droidman

回答

31

你應該在文檔被引用

@android:style/Widget.Holo.ActionBar.TabView 

錯字 - 他們不放過android:

+0

'''@android:style''',不是嗎? – elimirks

+0

@elimirks是的,修復,謝謝。 –

1

這就是你需要做什麼:

創建爲您的應用風格: 這裏我我正在自定義選項卡欄和它的文本(我正在使用基本兼容性主題,但您可以使用HOLO或任何您喜歡的):

<style name="AppTheme" parent="Theme.AppCompat.Light"> 
     <item name="android:actionBarTabTextStyle">@style/TabTextStyle</item> 
     <item name="android:actionBarTabStyle">@style/TabBarStyle</item> 

     <!-- Support library compatibility (ActionBarCompat) --> 
     <item name="actionBarTabTextStyle">@style/TabTextStyle</item> 
     <item name="actionBarTabStyle">@style/TabBarStyle</item> 
    </style> 

創建這些樣式:

<style name="TabTextStyle" parent="@style/Widget.AppCompat.ActionBar.TabText"> 
    <item name="android:textColor">@color/ab_tab_txt</item> 
</style> 

<style name="TabBarStyle" parent="@style/Widget.AppCompat.ActionBar.TabView"> 
    <item name="android:background">@drawable/tab_indicator</item> 
</style> 

對於顏色和繪圖,您可以創建一個選擇,允許根據點擊和選擇選項卡更改:

文件:RES /彩色/ ab_tab_txt (我用從RES /價值彩色文件設置我的常量,但你可以把顏色像這樣:#FFF)

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
     <item android:state_selected="true" android:color="@color/ab_tab_txt_selected"/> 
     <item android:color="@color/ab_tab_txt_unselected"/> 
    </selector> 

文件RES /繪製/ tab_indicator

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- Non focused states --> 
    <item android:state_focused="false" 
     android:state_selected="false" 
     android:state_pressed="false" 
     android:drawable="@android:color/transparent" /> 
    <item android:state_focused="false" 
     android:state_selected="true" 
     android:state_pressed="false" 
     android:drawable="@drawable/tab_selected_example" /> 

    <!-- Focused states --> 
    <item android:state_focused="true" 
     android:state_selected="false" 
     android:state_pressed="false" 
     android:drawable="@drawable/tab_unselected_focused_example" /> 
    <item android:state_focused="true" 
     android:state_selected="true" 
     android:state_pressed="false" 
     android:drawable="@drawable/tab_selected_focused_example" /> 

    <!-- Pressed --> 
    <!-- Non focused states --> 
    <item android:state_focused="false" 
     android:state_selected="false" 
     android:state_pressed="true" 
     android:drawable="@drawable/tab_unselected_pressed_example" /> 
    <item android:state_focused="false" 
     android:state_selected="true" 
     android:state_pressed="true" 
     android:drawable="@drawable/tab_selected_pressed_example" /> 

    <!-- Focused states --> 
    <item android:state_focused="true" 
     android:state_selected="false" 
     android:state_pressed="true" 
     android:drawable="@drawable/tab_unselected_pressed_example" /> 
    <item android:state_focused="true" 
     android:state_selected="true" 
     android:state_pressed="true" 
     android:drawable="@drawable/tab_selected_pressed_example" /> 
</selector> 

我繪製的文件是我透過這個有用的工具NinePatches: http://jgilfelt.github.io/android-actionbarstylegenerator/

+0

問題是SDK無法解析@style/Widget.AppCompat.ActionBar.TabView請檢查我的更新問題 – Droidman

+0

嗯,是的,我正在使用AppCompat獲取較低的API版本。 除非你確實需要使用Min SDK 14,否則你可以使用ActionBarCompat來將任何設備下載到SDK 7. 無論如何,對你而言,這應該是有用的:http://android-developers.blogspot.se/2011/04 /customizing-action-bar.html – CristianGuerrero

+0

將其更改爲Widget.Holo.ActionBar – CristianGuerrero