Usage of Android UI control switch

Switches are occasionally used in Android. Switch is a good control that is simple and easy to use.

First, add a switch control to the layout:

The following are common properties of this control:

Texton: text displayed when the control is opened textoff: text displayed when the control is closed thumb: picture of the control switch track: track picture of the control switch typeface: set the font type switchminwidth: switch minimum width switchpadding: set the blank distance between the switch and the text switchtextappearance: set the style of the text checked: set the initial selected state sp Littrack: whether to set a gap to separate the slider from the bottom picture (API 21 and above) showtext: whether to display the text on the switch (API 21 and above)

We generally do not use the original style of the control, so we need to modify the style ourselves:

gray_ thumb.xml:

green_ thumb.xml:

gray_ track.xml:

green_ track.xml:

thumb.xml:

track.xml:

Add the following style to styles.xml:

Finally, you only need to instantiate the control for corresponding operations:

MainActivity.class:

The final effect is as follows:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>