Tags
Android
Asked 3 years ago
15 Sep 2021
Views 334
Jalon

Jalon posted

How to disable button in android ?


<Button
  android:id="@+id/colorbutton"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/Change color"
/>
kord

kord
answered Sep 15 '21 00:00

if you want to make the button disable programmatically than use following code :


Button colorbutton = (Button) findViewById(R.id.colorbutton);
colorbutton.setEnabled(false);


setEnabled() method can used to disable by passing boolean false as parameter to it.
jaman

jaman
answered Sep 15 '21 00:00

add android:enabled="false" at Button tag in xml file

and final would be like this

<Button
  android:id="@+id/colorbutton"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/Change color"
       android:enabled="false"
/>

android:enabled properties is default true, if you put a false value on it, button will remain disabled
Post Answer