Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable an ImageButton?

I wanted to leave an ImageButton is disabled (not clickable) but have used android: enabled = "false" and does't work.

Does anyone know how to disable an ImageButton?

like image 906
Pedro Avatar asked Jun 25 '10 12:06

Pedro


People also ask

How to disable Image button?

If you want make enable = false in XML for ImageButton you have to add android:focusable="false" and android:clickable="false" . In fact, setting android:enabled to "false" DOES disable an ImageButton; the button doesn't receive lick events anymore.

How to disable an Image in JavaScript?

Setting the draggable HTML Attribute to false To do the same thing with JavaScript, we can use the setAttribute method: const img = document. querySelector('img') img. setAttribute("draggable", false);

How do you scale ImageButton?

How to programatically resize and show them? Use a android:scaleType="fitCenter" to have Android scale the images, and android:adjustViewBounds="true" to have them adjust their bounds due to scaling. All of these attributes can be set in code on each ImageButton at runtime.


2 Answers

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.

like image 88
GKeps Avatar answered Sep 23 '22 07:09

GKeps


You can use the android:clickable attribute on the XML, or the setClickable(boolean) method from your code.

like image 34
Cristian Avatar answered Sep 23 '22 07:09

Cristian