我制作了一个包含3种状态的按钮选择器-默认、聚焦和;启用/激活。我的意向id默认显示@drawable/normal
;触摸/按下时的@drawable/focused
;按钮启用时的@drawable/enabled
。但它不起作用&仅显示默认(正常)可绘制。
可绘制hdpi/button_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/enabled" android:state_pressed="true"></item>
<item android:drawable="@drawable/focused" android:state_focused="true"></item>
<item android:drawable="@drawable/normal"></item>
</selector>
layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/AppBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".RitualMainActivity" >
<include layout="@layout/merge_separator" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/button_selector" />
</LinearLayout>
使用ImageButton而不是imageview。默认情况下,图像视图不可点击,请参阅选择器不适用于布局和图像视图
试试这个。。。。通过添加可点击属性。。你可以解决的问题
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="@drawable/button_selector" />