Custom graphic objects not working in library projects

Any search for any information on how to provide your own custom state for use in the drop-down list selector pulls very little, but almost all of them (here and elsewhere) refer to this publication of google groups .

I have getters and setters like this: (Not included in the post above, but use their wording to keep them simple)

public void setFried(boolean fried){
    if(mFried != fried){
        mFried = fried;
        refreshDrawableState();
    }
}

public void isFried(){
    return mFried;
}

I am trying to get it to work for the last couple of hours and nothing is working. It just does not change the look. I looked at what happened when he called onCreateDrawableState (), and I looked at what would get from getDrawableState () after I changed the custom state. User state values ​​actually appear in the drawableState array.

Since I see that the state is actually merging with the array, and since it seems to completely ignore any of my user state in the selector, I think the xml should be wrong.

Here is what the post suggested:

<selector xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res/my.app.package">

   <item android:drawable="@drawable/item_baked" state_baked="true"
      state_fried="false" />
   <item android:drawable="@drawable/item_fried" state_baked="false"
      state_fried="true" />
   <item android:drawable="@drawable/item_overcooked" state_baked="true"
      state_fried="true" />
   <item android:drawable="@drawable/item_raw" state_baked="false"
      state_fried="false" />
</selector>

Can you just write state_fried and state_baked or do they need a prefix like app: state_fried? If I try to add a prefix, I will get a console error, for example:No resource identifier found for attribute 'state_fried' in package my.app.package

- ? , , - ?

, - , Android, attr.xml .

, , . . , , .

, ...

+3
2

. IIRC, , Android -, . ; . app: . my.app.package xmlns.

+2

xmlns:app="http://schemas.android.com/apk/lib/my.app.package

, .

+1

Source: https://habr.com/ru/post/1791408/


All Articles