找不到与给定名称匹配的资源:属性'android:tabLayout'

5

我想通过使用自己的样式替换标签页小部件的样式来进行自定义。我要替换的项如下:

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

但是我遇到了这个错误: 找不到与给定名称匹配的资源:属性 'android:tabLayout'
我已经像这样设置了父样式:
<style name="customTabWidget" parent="@android:style/Widget.Holo.TabWidget">

项目构建目标:Android 4.0

我已经清理了项目,但错误仍然存在。如何解决这个错误?

提前感谢。


1
tabLayout目前是一个非公开属性。这里有一个跟踪该问题的bug:https://code.google.com/p/android/issues/detail?id=65832 如果要以这种方式自定义TabWidget,则可能需要使用TabSpec.setIndicator进行编程处理。 - Klaus
1个回答

2

我遇到了一个类似的问题。解决方法至少包含在将tabLayout属性添加到res/values/attrs.xml文件中。以下是从android-16平台复制的TabWidget样式定义(请注意末尾的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">...

to:

 <item name="tabLayout">...

这个解决方案似乎对我没有帮助。还有其他事情我应该做但在回答中没有提到的吗? - Sergei Ledvanov
我写下了那个答案相当长的一段时间。现在看它,脑海中没有任何想法。抱歉! - Derek Kurth
这不是解决方案。它只能允许编译代码,仅此而已。Android不会使用自定义属性,因为它对此一无所知。 - Enyby

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接