Android 布局错误 : "Resource id <res_id> is not of type STYLE (instead attr)"

标签 android android-layout layout resources android-resources

我看到一个我以前从未见过的错误,它阻止了我的一些布局文件在 Eclipse 中呈现。它们在运行时渲染良好。

图形布局编辑器(和我的错误日志)中显示的错误是: “资源 id 0x1010081 不是 STYLE 类型(而是 attr)”

我在我的 R 文件中搜索了资源 id 0x1010081,但我找不到它,所以我猜测也许我与内置的 Android attr 有冲突。我还验证了我下面的所有样式属性都指向实际样式而不是 attr。任何帮助表示赞赏。

这是我的完整布局代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bkg_light"
    android:padding="@dimen/padding_med" >

    <RelativeLayout
        android:id="@+id/relativeLayout_activity"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/button_height"
        android:background="@drawable/xml_button"
        android:padding="@dimen/padding_med" >

        <TextView            
            style="@style/text_large_bold_white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:text="@string/activity" />

        <TextView
            android:id="@+id/textView_activity"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginRight="@dimen/margin_med"
            android:layout_toLeftOf="@+id/textView_arrow_right_start_date" 
            android:text="@string/none_selected"/>

        <TextView
            android:id="@+id/textView_arrow_right_start_date"
            style="@style/arrow_right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true" />
    </RelativeLayout>

    <!-- kv Duration -->

    <RelativeLayout
        android:id="@+id/relativeLayout_duration"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relativeLayout_activity"
        android:layout_marginTop="@dimen/margin_large"
        android:background="@drawable/xml_button">

        <TextView
            android:id="@+id/textView_duration"
            style="@style/text_large_bold_white"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:text="@string/duration_lc" 
            android:paddingLeft="@dimen/padding_med"/>

        <Spinner
            android:id="@+id/spinner_duration"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/button_height"
            android:layout_alignParentRight="true"
            android:entries="@array/array_durations"
            android:prompt="@string/duration_lc"
            android:spinnerMode="dropdown" 
            android:clickable="false"/>
    </RelativeLayout>

</RelativeLayout>

这是我的styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="arrow_right">
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">@dimen/text_xxlarge</item>
        <item name="android:text">@string/arrow_right</item>
    </style>

    <style name="button_blue">
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:background">@drawable/selector_button_blue</item>
        <item name="android:padding">@dimen/padding_med</item>
    </style>

    <style name="button_blue_small">
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:background">@drawable/selector_button_blue_small</item>
        <item name="android:padding">@dimen/padding_med</item>
    </style>

    <style name="button_dark">
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:background">@drawable/selector_button_dark</item>
        <item name="android:padding">@dimen/padding_med</item>
    </style>

    <style name="button_light">
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@color/black</item>
        <item name="android:background">@drawable/selector_button_light</item>
        <item name="android:padding">@dimen/padding_med</item>
    </style>

    <style name="button_light_small">
        <item name="android:textStyle">bold</item>
        <item name="android:textColor">@color/black</item>
        <item name="android:textSize">@dimen/text_small</item>
        <item name="android:background">@drawable/selector_button_light</item>
        <item name="android:padding">@dimen/padding_small</item>
    </style>  

    <style name="text_small_gray_light">
        <item name="android:textSize">@dimen/text_small</item>
        <item name="android:textColor">@color/gray_light</item>
    </style>

    <style name="text_med_bold_gray_light">
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">@dimen/text_med</item>
        <item name="android:textColor">@color/gray_light</item>
    </style>    

    <style name="text_large_bold_white">
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">@dimen/text_large</item>
    </style>

    <style name="text_large_bold_black">
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">@dimen/text_large</item>
        <item name="android:textColor">@color/black</item>
    </style>

    <style name="text_large_bold_gray_dark">
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">@dimen/text_large</item>
        <item name="android:textColor">@color/gray_dark</item>
    </style>

    <style name="text_large_bold_gray_light">
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">@dimen/text_large</item>
        <item name="android:textColor">@color/gray_light</item>
    </style>

    <style name="text_large_bold_white">
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">@dimen/text_large</item>
        <item name="android:textColor">@color/white</item>
    </style>

    <style name="text_large_white">
        <item name="android:textSize">@dimen/text_large</item>
        <item name="android:textColor">@color/white</item>
    </style>
</resources>

这是我的自定义 theme.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Theme.P90X" parent="@style/Theme.Sherlock">
        <item name="android:textColor">#ffffffff</item>
    </style>
</resources>

最佳答案

我也有这个问题,显示相同的资源 ID。当我将 android:spinnerMode 更改为 "dialog" 时它消失了,所以我怀疑这不是您的代码的问题。

有问题的 id 指的是 android 属性 spinnerStyle。见文档 R.attr

我找到了一个解决方法,即替换

android:spinnerMode="dropdown"

android:spinnerStyle="@android:style/Widget.Spinner.DropDown".

关于Android 布局错误 : "Resource id <res_id> is not of type STYLE (instead attr)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14758734/

相关文章:

java - 如何使用 Cloudinary api 从上传的视频中检索缩略图?

android - ?attr/selectableItemBackground 的定义和确切功能

android - 在布局的右侧和底部添加阴影

html - 更改文本溢出到下一行的跨度高度

java - 如何用Java快速做出想要的布局

android - qt-creator android部署错误

android - 异步任务中的进度对话框未关闭

android - 如何定义适用于 720p 和 1080p 屏幕的布局?

java - 为什么我的线性布局与 ListView 中的父级高度不匹配?

javascript - 使用 dagre 布局调整 cytoscape.js 中的形状大小