【问题标题】:no resource found for @style/Widget.Holo.ActionBar.TabView没有找到 @style/Widget.Holo.ActionBar.TabView 的资源
【发布时间】:2013-08-21 16:49:14
【问题描述】:

我正在尝试按照 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>

【问题讨论】:

  • 抱歉,忘记接受了。您的建议有效,谢谢

标签: android android-styles


【解决方案1】:

你应该参考

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

文档中的错字 - 他们省略了 android:

【讨论】:

  • @android:style,不是吗?
【解决方案2】:

这是你需要做的:

为您的应用创建样式: 在这里,我正在自定义 Tab Bar 和它的文本(我使用的是基本兼容性主题,但你可以使用 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/

【讨论】:

  • 问题是SDK无法解析@style/Widget.AppCompat.ActionBar.TabView 请查看我的更新问题
  • 嗯,是的,我将 AppCompat 用于较低的 API 版本。除非您真的需要使用 Min SDK 14,否则您可以将 ActionBarCompat 用于任何设备,直到 SDK 7。无论如何,在您的情况下,这应该很有用:android-developers.blogspot.se/2011/04/…
  • 改成 Widget.Holo.ActionBar
  • 当我改变它时,它只是将那个可绘制对象拉伸到整个选项卡区域。我只需要更换选项卡下方的蓝色指示器。文档说:仅限 Android 3.0 及更高版本:
  • 您需要查看我之前发布的链接。我发布的方式是您应该这样做的官方新方式。但是,由于您只需要 Holo 支持,您应该这样做:(我再次发布)android-developers.blogspot.se/2011/04/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-10
  • 2014-01-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多