为什么它说错误“找不到匹配的资源”,即使它存在?

时间:2013-08-10 14:04:53

标签: android

错误消息

error: Error: No resource found that matches the given name (at 'style' with value '@style/rightBehindMenuScroll').

布局/ activity_behind_right_simple.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/rightBehindMenuScroll" >

    <LinearLayout style="@style/behindMenuScrollContent"
        android:paddingTop="25dp" >
        <TextView
            style="@style/behindMenuItemTitle"
            android:text="Right" />
        <TextView
            style="@style/behindMenuItemLabel"
            android:text="Item0" />
        <TextView
            style="@style/behindMenuItemLabel"
            android:text="Item1" />
        <Button
            android:id="@+id/behind_btn"
            style="@style/behindMenuItemLabel"
            android:text="BUTTON" />
    </LinearLayout>
</ScrollView>

值/ styles.xml

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>


    <style name="leftBehindMenuScroll">
        <item name="android:layout_width">240dp</item>
        <item name="android:layout_height">fill_parent</item>
        <item name="android:background">@drawable/leftbg</item>
    </style>
    <style name="rightBehindMenuScroll">
        <item name="android:layout_width">200dp</item>
        <item name="android:layout_height">fill_parent</item>
        <item name="android:background">@drawable/rightbg</item>
    </style>
    <style name="behindMenuScrollContent">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">fill_parent</item>
        <item name="android:orientation">vertical</item>
        <item name="android:padding">8dp</item>
    </style>
    <style name="behindMenuItemTitle">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginLeft">8dp</item>
        <item name="android:layout_marginBottom">8dp</item>
        <item name="android:textSize">22sp</item>
        <item name="android:textColor">#FFFFFF</item>
    </style>
    <style name="behindMenuItemLabel">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_marginLeft">8dp</item>
        <item name="android:layout_marginBottom">8dp</item>
        <item name="android:textSize">18sp</item>
        <item name="android:textColor">#FFFFFF</item>
    </style>

</resources>

1 个答案:

答案 0 :(得分:1)

多数民众赞成你使用styles.xml而不是style.xml。

尝试更改referance,如下所示......

 <TextView
            style="@styles/behindMenuItemTitle"
            android:text="Right" />

与styles.xml文件的所有其他参考文件相同......