Android 布局错误:"Resource id <res_id>不是 STYLE 类型(而是 attr)" [英] Android layout error: "Resource id <res_id> is not of type STYLE (instead attr)"

查看:18
本文介绍了Android 布局错误:"Resource id <res_id>不是 STYLE 类型(而是 attr)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm seeing an error I've never seen before w/ Android that's preventing some of my layout files from rendering in Eclipse. They render fine at runtime.

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

The error that shows up in the graphical layout editor (and my Error log) is: "Resouce id 0x1010081 is not of type STYLE (instead attr)"

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

I've searched for resource id 0x1010081 in my R files, and I can't find it so I'm guessing maybe somehow I have a conflict with a built in Android attr. I've also verified that all of my style attributes below point to actual styles and not attr. Any help appreciated.

这是我的完整布局代码:

Here's my full layout code:

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

And here's my 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:

And here's my custom 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" 时它消失了,所以我怀疑这不是你的代码的问题.

I also have this problem, with the same resource ID showing up. It disappears when I change android:spinnerMode to "dialog" so I suspect it's not a problem with your code.

有问题的 id 指的是 android 属性 spinnerStyle.请参阅 R.attr

The id in question refers to the android attribute spinnerStyle. See the doc for R.attr

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

I found a workaround, namely replace

android:spinnerMode="dropdown"

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

这篇关于Android 布局错误:&quot;Resource id &lt;res_id&gt;不是 STYLE 类型(而是 attr)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆