Toggle的控件用法:ToggleButton状态开关按钮
activity_toggle.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开启WLAN" android:textSize="20dp" /> <ToggleButton android:id="@+id/togglebutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textOn="关闭" android:textOff="打开" /> </LinearLayout> </LinearLayout> ------------------------------------------------------------------------------------------------------- ToggleActivity.java
package com.example.app6; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Toast; import android.widget.ToggleButton; public class ToggleActivity extends Activity { //声明ToggleButton private