tags:

views:

286

answers:

1

I've created a class that extends drawable that I'd like to reference inside a resource xml. I happen to need it in a selector, like so:

<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
<item android:state_window_focused="false" android:state_pressed="false" 
android:drawable="com.sample.android.contacts.TopBarCollapsed"
/>
<item android:state_window_focused="true" android:state_pressed="true" android:drawable="@drawable/top_switcher_collapsed_selected" />
<item android:state_focused="true" android:drawable="@drawable/top_switcher_collapsed_focused" />

com.sample.android.contacts.TopBarCollapsed is the class that extends drawable.

A: 

For custom view classes in a resource xml checkout this example:

http://developer.android.com/guide/topics/ui/custom-components.html#modifying

Not sure if that applies to classes that extend Drawable, but its worth a try... One other thing, I kept missing this note toward the bottom for classes defined in their own class file:

If your custom View component is not defined as an inner class, then you can, alternatively, declare the View component with the XML element name, and exclude the class attribute. For example:

<com.android.notepad.MyEditText
 id="@+id/note"
 ... />
Churlbong