Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selector not working with layout and image view

Tags:

I want to use selector for a layout and image view..But it is not working for me. When I changed image view to imagebutton or button, it works fine. Any help will be greatly appreciated.. Thanks in advance..

here is the xmls I used..

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_pressed="true"
        android:drawable="@drawable/bg" 
        />
    <item
        android:drawable="@drawable/bg_01" />
</selector> 

The layout xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:layout_height="fill_parent">
    <ImageButton
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:text="layout tester"
        android:textColor="#000000"
        android:textStyle="bold"
        android:paddingTop="10dp"
        android:src="@drawable/testselector"
        android:layout_gravity="center_horizontal" />
    </LinearLayout>
like image 795
subair_a Avatar asked Jun 02 '11 10:06

subair_a


1 Answers

I ran into this problem just now. You'll have to set the LinearLayout to clickable. You can either do this in the XML with

android:clickable="true"

Or in code with

yourLinearLayout.setClickable(true);
like image 128
Rockmaninoff Avatar answered Oct 03 '22 13:10

Rockmaninoff