How to Disable Button in Android Studio

anooppatel

Anoop Patel

Posted on September 21, 2024

How to Disable Button in Android Studio

*First Way: *

button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                view.setEnabled(false);
            }
        });
Enter fullscreen mode Exit fullscreen mode

Second way: Without setOnClickListner

 public void disable(View v){
        v.setEnabled(false);
    }
Enter fullscreen mode Exit fullscreen mode

*XMl code file: *

 <Button
        android:id="@+id/button"
        android:onClick="disable"
        android:layout_margin="8dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button" />
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
anooppatel
Anoop Patel

Posted on September 21, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

How to Disable Button in Android Studio
androiddev How to Disable Button in Android Studio

September 21, 2024