How to disable an Android button?
Did you try this?
myButton.setEnabled(false);
Update: Thanks to Gwen. Almost forgot that android:clickable
can be set in your XML layout to determine whether a button can be clickable or not.
How to disable a button in Kotlin?
Just to disable a button .
button.isEnabled = false
button.isClickable = false
and If you want to disable a button , and want to grey out its color & background ,you can do something like this -
fun markButtonDisable(button: Button) {
button?.isEnabled = false
button?.setTextColor(ContextCompat.getColor(textView.context, R.color.white))
button?.setBackgroundColor(ContextCompat.getColor(textView.context, R.color.greyish))
}
Disabling a Button with an icon
Create a new grayed icon and add both inside a selector.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/icon_ok" android:state_enabled="true" />
<item android:drawable="@drawable/icon_ok_disabled" android:state_enabled="false" />
</selector>
Use inside button like: android:drawableStart="@drawable/selector"
For TextColor,
Create another selector inside res/color/mycustomtextcolor.xml
:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#666" android:state_enabled="false" />
<item android:color="#000" android:state_enabled="true"/>
</selector>
Inside your widget call using: android:textColor="@color/mycustomtextcolor"
Or
inside your style
add another item using: <item name="android:textColor">@color/mycustomtextcolor</item>
How to disable button click?
case R.id.next:
Log.i("Tag","tag");
if(imageCounter < imageList.length)
{
imageCounter++;
imagePath = imageList[imageCounter];
if (imageCounter==(imageList.length)-1)
{
ImageButton next=(ImageButton)findViewBYId(R.id.next);
next.setEnabled(false);
}
}
break;
case R.id.back:
if(imageCounter > 0)
{
imageCounter--;
imagePath = imageList[imageCounter];
if (imageCounter==0)
{
ImageButton back=(ImageButton)findViewBYId(r.id.back);
back.setEnabled(false);
}
}
break;
How to disable button once it is clicked and enable it again once another button is clicked in android
Try this one
// Create a global button variable
Button flagButton = null;
Button.OnClickListener btnOnClickListner = new Button.OnClickListener() {
@Override
public void onClick(View v) {
if(flagButton == null)
flagButton = (Button)v;
else
flagButton.setEnabled(true);
v.setEnabled(false);
flagButton = (Button)v;
if (v == btn1)
// my code
else if (v == btn2)
// my code
else if (v == btn3)
// my code
else if (v == btn4)
// my code
}
}
How to disable dot button in android Kotlin
so you want to disable the button that has the name dotButton
after the user clicks it for the first time :
to disable a button, use:
dotButton.isClickable=false
if you want the button to become clickable again(like when the user deletes the dot that he already pressed) you can use:
dotButton.isClickable=true
Edit:
modify your activity code like that :
when (button.id) {
buttonOne.id -> isClicked += "1"
buttonTwo.id -> isClicked += "2"
buttonThree.id -> isClicked += "3"
dotButton.id-> {
isClicked+="."
dotButton.isClickable=false//**add this line here**
}
}
fun clearFunction(view: View){
viewResult.setText("")
dotButton.isClickable=true//**add this line here**
}
Related Topics
Context.Startforegroundservice() Did Not Then Call Service.Startforeground()
How to Add Calendar Events in Android
How to Sign Android App With System Signature
Android - Cancel Asynctask Forcefully
How to Add a Library Project to a Android Project
Where Does Android Emulator Store SQLite Database
How to Use Opencv in Using Gradle
How to Attach Javadoc or Sources to Jars in Libs Folder
Calling a Fragment Method from a Parent Activity
Custom Notification Layouts and Text Colors
Android Pick Images from Gallery
How to Return a Result (Startactivityforresult) from a Tabhost Activity
How to Find Serial Number of Android Device
Noclassdeffounderror For Code in an Java Library on Android
Android Difference Between Two Dates
The Setmobiledataenabled Method Is No Longer Callable as of Android L and Later