Detailed explanation and example code of Android togglebutton
Detailed explanation of Android togglebutton
During the development of Android, the use frequency of togglebutton is also quite high. Let me talk about two ways to use this component.
The first is simple use, using toast to pop up prompt statements
It should be noted that to customize the displayed content of togglebutton, you need to set its texton and textoff content.
Then the main display code:
The next is a more complex use case, which is to cooperate with ImageView to realize different picture display states
Then the activity code
It should be noted that we also need to declare it before using it, otherwise we will report an error of null pointer.
Here are the results after the program runs
Summary and assumption:
Generally speaking, the togglebutton used in the use process is not so simple, but the main idea and framework are still based here. We can add to the relevant listening methods, such as mute processing, or status change, etc. In this way, our application will become more flexible.