2013-08-21 80 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