Tôi muốn nút hình ảnh có hai trạng thái i) bình thường ii) chạm (hoặc nhấp).
Tôi đã đặt hình ảnh bình thường trong nền nút hình ảnh và tôi đang cố gắng thay đổi hình ảnh (được nhấn) từ phương pháp onclick , nhưng nó không thay đổi.
Tôi muốn rằng nếu tôi nhấn nút hình ảnh thì hình ảnh sẽ thay đổi từ bình thường sang nhấn cho đến khi tôi nhấn nút khác nhưng nó không xảy ra .
Bất cứ ai có thể gợi ý cho tôi cách tôi có thể làm điều này với bộ chọn hoặc tại thời điểm chạy không?
Đây là mã imagebuttonpanel của tôi.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="bottom"
android:id="@+id/buttonpanel">
<ImageButton android:id="@+id/buttonhome"
android:layout_width="80dp"
android:layout_height="36dp"
android:focusable="true"
android:background="@drawable/homeselector">
</ImageButton>
<ImageButton android:id="@+id/buttonsearch"
android:layout_height="36dp"
android:layout_width="80dp"
android:background="@drawable/searchselector"
android:focusable="true">
</ImageButton>>
<ImageButton android:id="@+id/buttonreg"
android:layout_height="36dp"
android:layout_width="80dp"
android:background="@drawable/registerselector"
android:focusable="true">
</ImageButton>>
<ImageButton android:id="@+id/buttonlogin"
android:layout_height="36dp"
android:layout_width="80dp"
android:background="@drawable/loginselector"
android:focusable="true">
</ImageButton>
</LinearLayout>
và bộ chọn xml của tôi là
<?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/homehover"
/> <item android:state_focused="true" android:drawable="@drawable/homehover"
/> <item android:drawable="@drawable/home" /> <item android:state_window_focused="true"
android:drawable="@drawable/homehover" /> -->
<item android:state_enabled="false" android:drawable="@drawable/homehover" />
<item android:state_pressed="true" android:state_enabled="true"
android:drawable="@drawable/homehover" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/homehover" />
<item android:state_enabled="true" android:drawable="@drawable/home" />
</selector>
Và tôi cũng đã cố gắng thay đổi tài nguyên hình ảnh trên sự kiện ontouch và onclick, nhưng không giúp được gì.