How to bring up a message when you click on a disabled button?

I have some disabled * buttons in my android app. How can I light a message when you try to click on them?

+3


source to share


3 answers


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
}

      

+4


source


public String yabadabado="";


//OnCreate...

//Whatever action that disables button
button.setEnabled(false);
String yabadabado ="toastmessage";

//button.onClick....
if (yabadabado.equals("toastmessage"))
{toast your message}
else
{some other action}

      



0


source


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.

0


source







All Articles