How to disable an ImageButton

Welcome to ScriptMode
Rami
Posts: 36
Joined: Tue Aug 25, 2015 9:39 am

How to disable an ImageButton

Postby Rami » Wed Mar 02, 2016 7:16 am

This looks easy, but I'm not able to disable an ImageButton. It continues to receive click events, and its appearance don't change like a standard Button would.

There are some similar questions on SO, but they don't help me.

Even with a very simple layout like this :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<ImageButton
android:id="@+id/btn_call"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:clickable="false"
android:enabled="false"
android:src="@android:drawable/sym_action_call" />

</LinearLayout>
The button is still enabled and I can click it.

What's strange is that if I change the ImageButton to a simple Button, then it works as expected. The button becomes disabled and unclickable. I don't understand. Does anyone have an idea?

Paul
Posts: 137
Joined: Mon Aug 24, 2015 4:53 pm

Re: How to disable an ImageButton

Postby Paul » Fri Mar 04, 2016 1:36 pm

If you want to show the button as disabled (if you have that set up in an xml drawable file) doing both setClickable(false) AND setEnabled(false) will do the trick.


Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest