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
?
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.
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 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.
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.
You can use the android:clickable
attribute on the XML, or the setClickable(boolean)
method from your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With