How to bring up a message when you click on a disabled button?
how to disable the power button of an activated button?
first you need to create two backgrounds disabled.xml and enabled.xml here is a website to help you do that http://angrytools.com/android/button/ put them in a folder / folder
here's how to show the button as disabled.
button.setBackgroundResource(R.drawable.disabled);
to show it as included
button.setBackgroundResource(R.drawable.enabled);
add a boolean variable that allows us to know the state of the button
boolean disabled=true ;//if the button is disabled at first
and then when you enable the button, change the background and boolean value
disabled=false; button.setBackgroundResource(android.R.enabled);
and when you turn it off
disabled=true; button.setBackgroundResource(android.R.disabled);
how to use: add this to the click listener button
if(disabled){
Toast.makeText(this,"Button disabled",Toast.LENGTH_SHORT).show();
}else {
//do what you want when button is enabled
}
source to share
My Solution involves creating two buttons.
A on a button that looks good and normal and has a normal click
An off button that looks like a power button but is off and off on. Click.
Do both of these dynamically with java in activity and then switch them to container layout in XML file at runtime.
source to share