For beginners, click the ToggleButton and change the background image. Click again to restore the background image and the togglebutton background image.
The icon above, R. drawable. register_checked is the selected Image
The icon below, R. drawable. register_unchecked is the unselected Image
By default, the selected result is shown above. Click the button to cancel the selection. click the button again to select again.
Actually, this is two images. The key is that the image must be changed with the button.
At first, I wanted to use the Button to implement it. After a long time, I had to press the Button and release it. I didn't click it to change the background image.
After a long time, Baidu found the desired effect with ToggleButton, and shared it with you here.
XML:
Android: textOn = ""
Android: textOff = ""
If the text content is not set to null, the default text is displayed on the background image.
<ToggleButton
Android: id = "@ + id/btn_register_sms_confirm"
Android: layout_width = "30dip"
Android: layout_height = "24dip"
Android: textOn = ""
Android: textOff = ""
Android: background = "@ drawable/register_checked"/> <! -- Here is the selected image by default -->
JAVA:
Note when importing a package.
Import android. widget. CompoundButton. OnCheckedChangeListener;
Here is the selected status listening event, not the Click Event
FindViewById (R. id. btn_register_sms_confirm). setOnCheckedChangeListener (new OnCheckedChangeListener (){
@ Override
Public void onCheckedChanged (CompoundButton buttonView, boolean isChecked ){
BtnSmsConfirm. setChecked (isChecked );
BtnSmsConfirm. setBackgroundResource (isChecked? R. drawable. register_checked: R. drawable. register_unchecked );
}
});
Excel vba switch button (TOGGLEBUTTON) usage I want to use a switch button on my forms interface for continuous numbering
Switch button ??? Not understand
However, you can directly add a button "auto number"
Code function:
1. Obtain the current maximum number from the database
2. display the maximum number + 1 in this window
At the same time (must at the same time) input the content of the entire interface into the database
(Optional) If you want to enter new content on the current page, clear the content,
Can the toggleButton in android development be set to the ON status when one event is pressed OFF or another event occurs?
Can I listen to OnCheckedChangeListener?