Julian A.
Julian A.

Reputation: 11460

Is it possible to have a custom class be the drawable supplied to a selector?

Is it possible to have a custom class be the drawable supplied to a selector? The core question really is whether android supports having a drawable xml that references a custom class.

Here's the selector:

<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
  <item
      android:state_pressed="true"
      android:state_window_focused="true"
      android:drawable="@drawable/intensity_tick_empty" />
</selector>

Here's intensity_tick_empty.xml:

<?xml version="1.0" encoding="UTF-8"?>
<com.somepackage.android.RatingTick
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="20dip"
   android:layout_height="20dip"
   android:background="#CCCCCC" />

RatingTick is my custom class, and it extends View.

Thanks much!

Upvotes: 2

Views: 731

Answers (1)

Romain Guy
Romain Guy

Reputation: 98501

You can use custom drawables, but not from XML. You will have to build the selector from code to make it work.

Upvotes: 3

Related Questions