我正在尝试在this引用后自定义ActionBar的标签指示符,但是我收到了错误:
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 :(得分:31)
你应该引用
@android:style/Widget.Holo.ActionBar.TabView
文档中的错字 - 他们离开了android:
。
答案 1 :(得分:1)
这是你需要做的:
为您的应用创建一个样式: 在这里,我正在自定义Tab栏及其文本(我使用的是基本兼容性主题,但您可以使用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 / color / ab_tab_txt(我使用res / values中的颜色文件来设置我的常量,但你可以这样放置颜色:#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 / drawable / 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/