zoukankan      html  css  js  c++  java
  • 状态开关(ToggleButton)

    状态开关(ToggleButton):

    常用属性:isChecked(是否被选中,如true)

    监听:1.监听方法:setOnCheckedChangeListener

       2.监听器:CompoundButton.OnCheckedChangeListener

    1.Activity

    //状态的开关
    public class ToggleButtonActivity extends Activity {
    
        private ToggleButton toggleButton;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.toggle_button);
            
            toggleButton = (ToggleButton)findViewById(R.id.toggleButtonId);
            
            toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if(isChecked){
                        Toast.makeText(ToggleButtonActivity.this, "无线网络打开了!", Toast.LENGTH_SHORT).show();
                    }else{
                        Toast.makeText(ToggleButtonActivity.this, "无线网络关闭了!", Toast.LENGTH_SHORT).show();
                    }
                }
            });
        }
    }

    2.xml文件

    <?xml version="1.0" encoding="utf-8"?>
    <!-- 状态的开关页面 -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:padding="5dp" >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="无线网:"
            android:textSize="20sp" />
    
        <ToggleButton
            android:id="@+id/toggleButtonId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
    </LinearLayout>

    3.效果显示图

  • 相关阅读:
    configuring express for ejs
    if else in EJS
    nodegroupchat exercise
    heap&stack 区别
    如何构建积木式Web应用(引自微软CSDN )
    Configuring IIS: Mapping .* to the aspnet_isapi.dll
    递归遍历XML生成树
    数据库应用:无法更新到数据库
    C#中HashTable的用法
    如何使用Eclipse编译C,C++,JAVA程序
  • 原文地址:https://www.cnblogs.com/wuziyue/p/5470376.html
Copyright © 2011-2022 走看看