是否可以将自定义类作为提供给选择器的drawable?

时间:2011-01-30 18:48:59

标签: android drawable

是否可以将自定义类作为提供给选择器的drawable?核心问题是android是否支持具有引用自定义类的可绘制xml。

这是选择器:

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

这是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是我的自定义类,它扩展了View。

非常感谢!

1 个答案:

答案 0 :(得分:3)

您可以使用自定义drawable,但不能使用XML。您必须从代码构建选择器才能使其工作。