0
votes

I've made a button selector containing 3 states - default, focused & enabled/activated. My intentions id display @drawable/normal by default; @drawable/focused when touched/pressed; @drawable/enabled when button is enabled. But it is not working & only shows default(normal) drawable.

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

2 Answers

1
votes

use ImageButton instead of imageview.Imageview is not clickable as default please see selector not working with layout and image view

0
votes

Try this ....by adding clickable attribute.. you may solve the problem

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:background="@drawable/button_selector" />