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.效果图如下:

  • 相关阅读:
    更准确的mysql全文索引
    range
    牛顿冷却定律 使用
    Servo: The Embeddable Browser Engine
    Node.js V0.12新特性之性能优化
    Lodash,你正在使用的JavaScript库
    Python on Android
    Microsoft HoloLens 技术解谜(下)
    Microsoft HoloLens 技术解谜(上)
    市售体感设备横评
  • 原文地址:https://www.cnblogs.com/wuziyue/p/5372232.html
Copyright © 2011-2022 走看看