2012-08-05 70 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

相关问题