Set selector from style

SagarPanwalaSagarPanwala USMember ✭✭✭
edited September 2014 in Xamarin.Android

I have a selector.xml ,created in drawable.

        <selector xmlns:android="" >    

        <item android:state_pressed="true"

        <item android:state_focused="true" 

        <item android:drawable="@color/tabBackground" />

I want to use this file from my style file.

        <style name="Tab">
            <item name="android:background">@drawable/selector</item>

I have google it, there is lots of example with this sample, but I am getting error like
No resource found that matches the given name (at 'android:background' with value '@drawable/selector')

So, please help me..


  • ShailDShailD USMember ✭✭
    edited September 2014

    I tried this and it worked. Anyhow, just in case, try a different file-name such as tab_selector.xml instead of selector.xml.

    Also, your styles file should be named Styles.xml (plural of style).

  • FranzHaertlFranzHaertl USMember
    edited November 2014

    I have the very same problem. Are you sure ShailD that it works using a selector in a predefined Style in Styles.xml?
    When I try to declare something like <item name="android:background">@drawable/ListHighlight</item> I always get the error
    No resource found that matches the given name (at 'android:background' with value '@drawable/ListHighlight') like Sagar. Is it some secret naming-convention? Apparently there's others with that problem as well:

    EDIT: Odd. Now it works with a new selector file. I created the xml from scratch in VisualStudio, called it "fb_selector" upon creation, and copy/pasted the same content. Now it works. I tried some more selector files with various names, and sometimes it works, while sometimes it doesn't. So far it seems completely random to me which files work and which don't.

  • JoUtneJoUtne USMember

    Just ran into the same issue. Looks like a drawable selector doesn't like names with uppercase letters?

Sign In or Register to comment.