For beginners, click the ToggleButton and change the background image. Click again to restore the background image and the togglebutton background image.

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.