User Interface View switch

Source: Internet
Author: User

We have spent half of it before we know what life is.


What's in this lecture: switch control


Example one:


Here is the Res/layout/activity_main.xml layout file:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent " >    <textview        android:layout_width= "wrap_content"        android:layout_height= "Wrap_content        " android:layout_marginleft= "10DP"        android:text= "WiFi settings"        android:textsize= "20sp"/>    <switch        android:id= "@+id/open"        android:layout_width= "wrap_content"        android:layout_height= "wrap_content "         android:layout_alignparentright=" true "        android:layout_marginright=" 10DP "        android:texton=" WiFi on "        android:textoff=" WiFi off in "/></relativelayout>

here is the mainactivity main interface file:

public class Mainactivity extends Activity {private Switch open;protected void OnCreate (Bundle savedinstancestate) {Super . OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); open= (Switch) Findviewbyid (r.id.open); o Pen.setoncheckedchangelistener (New Oncheckedchangelistener () {public void oncheckedchanged (Compoundbutton Buttonview, Boolean isChecked) {if (isChecked) {Toast.maketext (mainactivity.this, "open WiFi", Toast.length_long). Show () ;} Else{toast.maketext (Mainactivity.this, "Off WiFi", Toast.length_long). Show ();}});}}



Take your time and enjoy it


User Interface View switch

Related Article

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.