繁体   English   中英

android布局文件中无法识别自定义XML属性

[英]Custom XML attributes are not recognized in android layout files

我正在使用这个小部件https://github.com/erikwt/PullToRefresh-ListView,并希望进行一些更改。 我已经定义了attrs.xml,以便能够从XML定义控制文本的颜色等。 但是我的自定义属性未被识别(错误是:在包'eu.erikw'中找不到属性'ptrContainerBackground'的资源标识符)。 我已经使用了在其他库项目中定义的自定义视图,到目前为止一切运行良好。 你能帮忙解决一下这个问题吗?

这是我的attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="eu.erikw.PullToRefreshListView">
    <attr name="ptrContainerBackground" format="integer"/>
    <attr name="ptrArrow" format="integer"/>
    <attr name="ptrTextColor" format="integer"/>
    <attr name="ptrTextSize" format="integer"/>
</declare-styleable>    
</resources>

这是布局文件中的视图定义:

<eu.erikw.PullToRefreshListView xmlns:ptr="http://schemas.android.com/apk/res/eu.erikw"
        android:id="@+id/lv_transactionsList"
        ptr:ptrTextColor="@color/text_white_color"
        ptr:ptrContainerBackground="@color/text_white_color"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@drawable/transactions_list_divider"
        android:dividerHeight="1dip"
        android:cacheColorHint="@color/stations_finder_item_bg">
</eu.erikw.PullToRefreshListView>

1)尝试清理项目,然后重新构建,和/或

2)检查eu.erikw是否是正确的包裹

的xmlns:PTR = “http://schemas.android.com/apk/res/eu.erikw”

这应该是

的xmlns:PTR =“http://schemas.android.com/apk/res/your_package_name

其中your_package_name是AndroidManifest.xml定义的应用程序包

3)不要使用点

declare-styleable name =“eu.erikw.PullToRefreshListView”>

因为这将难以在Java代码中检索attrs。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM