zoukankan      html  css  js  c++  java
  • 横向开关(switch)

    横向开关(switch)

    一:属性

    1.Activity

    //横向开关
    public class SwitchActivity extends Activity {
        
        private Switch switchComponent;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.switch_layout);
            
            switchComponent = (Switch)findViewById(R.id.switchId);
            
            switchComponent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if(isChecked){
                        Toast.makeText(SwitchActivity.this, "无线网络打开了!", Toast.LENGTH_SHORT).show();
                    }else{
                        Toast.makeText(SwitchActivity.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" />
    
        <Switch
            android:id="@+id/switchId"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:textOn="打开"
            android:textOff="关闭"
            />
    
    </LinearLayout>

    3.效果图如下:

  • 相关阅读:
    fastdfs部署及官网
    fasrdfs在spring cloud中的使用
    面包屑的查询
    SpringCloud中使用ES使用课程上下线
    Redis中在项目中的使用
    树结构Tree查询
    平凡的世界 田晓霞的日记 摘抄

    英语积累
    英语学习第四天
  • 原文地址:https://www.cnblogs.com/wuziyue/p/5372232.html
Copyright © 2011-2022 走看看