2012-08-05 67 views
5

我想通過用自己的樣式替換樣式來自定義選項卡窗口小部件。 我要更換產品如下:找不到與給定名稱匹配的資源:attr'android:tabLayout'

<item name="android:tabLayout">@android:layout/tab_indicator_holo</item> 

但我得到這個錯誤: 沒有資源發現在給定名稱匹配:ATTR「機器人:tabLayout」

我已經設置了家長風格是這樣的:

<style name="customTabWidget" parent="@android:style/Widget.Holo.TabWidget"> 

項目構建的目標:Android 4.0的

我也清理項目,但錯誤仍然存​​在。 如何修復錯誤?

在此先感謝。

+1

'tabLayout'目前是一個非公開的屬性。以下是跟蹤此問題的錯誤:https://code.google.com/p/android/issues/detail?id=65832如果您想以這種方式自定義TabWidget,您可能必須以編程方式使用[TabSpec.setIndicator](http ://developer.android.com/reference/android/widget/TabHost.TabSpec.html#setIndicator(android.view.View))。 – Klaus 2014-07-05 07:28:26

回答

2

我遇到了類似的問題。至少部分解決方案是將tabLayout屬性添加到res/values/attrs.xml。這裏的TabWidget風格的定義,從Android-16平臺複製(注意末尾的tabLayout屬性):

<declare-styleable name="TabWidget"> 
    <!-- Drawable used to draw the divider between tabs. --> 
    <attr name="divider" /> 
    <!-- Determines whether the strip under the tab indicators is drawn or not. --> 
    <attr name="tabStripEnabled" format="boolean" /> 
    <!-- Drawable used to draw the left part of the strip underneath the tabs. --> 
    <attr name="tabStripLeft" format="reference" /> 
    <!-- Drawable used to draw the right part of the strip underneath the tabs. --> 
    <attr name="tabStripRight" format="reference" /> 
    <!-- Layout used to organize each tab's content. --> 
    <attr name="tabLayout" format="reference" /> 
</declare-styleable> 

既然你要重寫,你也想改變:

<item name="android:tabLayout">... 

到:

<item name="tabLayout">... 
+0

這個解決方案似乎沒有幫助我。還有什麼我應該這樣做的,這個答案沒有提到嗎? – 2014-04-26 19:23:23

+0

我寫了一段回答。現在看,沒有什麼可以想到的。抱歉! – 2014-04-27 22:49:02

+0

這不是解決方案。它只允許編譯代碼。而已。 Android不會使用自定義屬性,因爲不知道它。 – Enyby 2017-08-19 05:16:06

相關問題