Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no resource found for @style/Widget.Holo.ActionBar.TabView

I'm trying to customize my ActionBar's tab indicator following this reference, however I'm getting the error:

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

Minimum SDK is set to 14, target SDK = 18. Any ideas?

EDIT:

I already have the following styles which work:

     <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>
like image 753
Droidman Avatar asked Aug 21 '13 16:08

Droidman


2 Answers

You should be referencing

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

Typo in the docs - they left off the android:.

like image 88
Paul Burke Avatar answered Nov 23 '22 13:11

Paul Burke


This is what you need to do:

Create a Style for your app: Here I am customizing the Tab Bar and it's text (I am using a base compatibility theme but you can use HOLO or anything you like):

   <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>

Create those styles:

<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>

For the color and drawables, you can create a selector that allows the tab to change based on clicks and selection:

File: res/color/ab_tab_txt (I am using the color file from res/values to set my constants, but you can place the color like so: #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>

File 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>

My drawable files are NinePatches that I create using this useful tool: http://jgilfelt.github.io/android-actionbarstylegenerator/

like image 25
CristianGuerrero Avatar answered Nov 23 '22 13:11

CristianGuerrero