styles.xml 中 自定义的item报错提示Cannot resolve symbol

img


styles.xml 中 自定义的item报错提示Cannot resolve symbol ‘abc’

题主写的这种格式style只能匹配系统默认提供的属性。如果想自己取名字需要如下:

<resources>

    <!--系统提供. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    
    <!--自定义-->
    <declare-styleable name="Custom">
        <attr name="abc" format="boolean"></attr>
        <attr name="def" format="integer"></attr>
    </declare-styleable> 

</resources>


“adb” 是自定义属性,需要在 declare-styleable 中定义,如下:

    <declare-styleable name="demo">
        <attr name="abc" format="integer"></attr>
    </declare-styleable>