2013-08-21 38 views
7

Tôi đang cố gắng để tùy chỉnh chỉ số tab ActionBar của tôi sau this tham khảo, tuy nhiên tôi nhận được lỗi:không tài nguyên tìm thấy cho @ style/Widget.Holo.ActionBar.TabView

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

tối thiểu SDK được thiết lập đến 14, nhắm mục tiêu SDK = 18. Bất kỳ ý tưởng nào?

EDIT:

Tôi đã có những phong cách sau đây mà làm việc:

 <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

Bạn vẫn còn ở đó? –

+0

oh xin lỗi, quên chấp nhận. Đề xuất của bạn hoạt động, cảm ơn – Droidman

Trả lời

31

Bạn nên tham khảo

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

Typo trong tài liệu - họ rời khỏi android:.

+0

'' '@android: style''', không? – elimirks

+0

@elimirks Yup, cố định, cảm ơn. –

1

Đây là những gì bạn cần làm:

Tạo một Style cho ứng dụng của bạn: Ở đây tôi đang tùy chỉnh Thanh tab và văn bản của nó (Tôi đang sử dụng chủ đề tương thích cơ sở nhưng bạn có thể sử dụng HOLO hoặc bất kỳ thứ gì bạn thích):

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

Tạo những phong cách:

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

Đối với màu sắc và drawables, bạn có thể tạo một selector cho phép các tab để thay đổi dựa trên nhấp chuột và lựa chọn:

File: res/màu/ab_tab_txt (tôi đang sử dụng tập tin màu sắc từ res/values ​​để thiết lập các hằng số của tôi, nhưng bạn có thể đặt màu sắc như vậy: #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> 

file drawable của tôi là NinePatches mà tôi tạo sử dụng công cụ này hữu ích: http://jgilfelt.github.io/android-actionbarstylegenerator/

+0

vấn đề là SDK không thể phân giải @ style/Widget.AppCompat.ActionBar.TabView Vui lòng kiểm tra câu hỏi updatet của tôi – Droidman

+0

Vâng vâng, tôi đang sử dụng AppCompat cho các phiên bản API thấp hơn. Trừ khi bạn thực sự cần sử dụng SDK tối thiểu 14, bạn có thể sử dụng ActionBarCompat cho bất kỳ thiết bị nào xuống SDK 7. Dù sao đi nữa, trong trường hợp của bạn, điều này sẽ hữu ích: http://android-developers.blogspot.se/2011/04 /customizing-action-bar.html – CristianGuerrero

+0

Thay đổi nó thành Widget.Holo.ActionBar – CristianGuerrero

Các vấn đề liên quan