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.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>