Set selector from style

SagarPanwalaSagarPanwala Sagar PanwalaUSMember ✭✭
edited September 2014 in Xamarin.Android

I have a selector.xml ,created in drawable.

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

        <item android:state_pressed="true"
              android:drawable="@color/red"/>

        <item android:state_focused="true" 
              android:drawable="@color/red"/>

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

I want to use this file from my style file.
Style.xml

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

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

Posts

  • ShailDShailD Shail Deliwala 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 Franz Haertl 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: stackoverflow.com/questions/25290433/android-styles-xml-cant-find-drawable-selector-for-textview-textcolor

    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 Jo Utne 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.