Android Switch: Switch control

Source: Internet
Author: User

What is a switch? Let's take a look at the switch implementation effect

It's like a button that turns on mobile data on your phone.

Property:

  • Android:showtext: Sets whether to display text when on/off, Boolean
  • Android:splittrack: whether to set a gap, let the slider and the bottom picture separated, Boolean
  • android:switchminwidth: Set the minimum width of the switch
  • android:switchpadding: Sets the spacing of text within the slider
  • android:switchtextappearance: Set the text appearance of the switch, temporarily did not find what use ...
  • Android:textoff: text displayed when the button is not selected
  • Android:texton: text displayed when the button is selected
  • Android:textstyle: text style, bold, italic underline those
  • android:track: picture at the bottom
  • android:thumb: Picture of the slider
  • android:typeface: setting fonts

It is easier to use this control, as long as it is referenced in the layout file and then set the associated property.

<?xml version="1.0"encoding="Utf-8"? ><linearlayout xmlns:android="http://schemas.android.com/apk/res/android"Xmlns:app="Http://schemas.android.com/apk/res-auto"Xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="match_parent"Android:layout_height="match_parent"android:gravity="Center"Tools:context="Com.contentprovide.liuliu.togglebutton_test. Mainactivity"> <Switch Android:id="@+id/swh"Android:layout_width="wrap_content"Android:layout_height="wrap_content" android:track="@drawable/tra"  android:thumb="  @drawable/a3" Android:textoff="off"Android:texton=" on"/></linearlayout>

My track and thumb reference two drawable resource files are defined by myself

Tra.xml

<?xml version="1.0"encoding="Utf-8"? ><selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_checked="true"android:drawable="@drawable/a2"></item><item android:state_checked="false"android:drawable="@drawable/a1"></item></selector>

A1.xml, A2.xml, A3.xml are custom graphics, relatively simple, here is not recorded

Android Switch: Switch control

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.