Filip Majernik
Filip Majernik

Reputation: 7810

Custom XML attributes are not recognized in android layout files

I am using this widget https://github.com/erikwt/PullToRefresh-ListView and wanted to make some changes. I have defined attrs.xml to be able to control the color of the text, etc. from the XML definition. However my custom attributes are not being recognized (the error is: No resource identifier found for attribute 'ptrContainerBackground' in package 'eu.erikw'). I have already used my custom views defined in other library projects and everything has worked well so far. Could you please help solve the problem?

Here is my 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>

And here is the view definition in the layout file:

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

Upvotes: 3

Views: 3363

Answers (1)

Vasu
Vasu

Reputation: 4982

1) Try to clean your project, and build again, and/or

2) check whether eu.erikw is the right package in

xmlns:ptr="http://schemas.android.com/apk/res/eu.erikw"

This should be

xmlns:ptr="http://schemas.android.com/apk/res/your_package_name

where your_package_name is your application package defined in your AndroidManifest.xml

3) Do not use dot(s) in

declare-styleable name="eu.erikw.PullToRefreshListView">

as this would make difficult to retrieve attrs in Java code.

Upvotes: 6

Related Questions