android开关控件使用(一)

android开关控件使用

package xueyou.xueyoucto.com.androidviews;


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Switch;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private final String Tag = "MAINACTIVITY";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void swtich1Click(View view){
        Switch sw = (Switch)view;
        boolean isChecked = sw.isChecked();
        if(isChecked){
            Toast.makeText(MainActivity.this, "开启", Toast.LENGTH_SHORT).show();
        }else {
            Toast.makeText(MainActivity.this, "关闭", Toast.LENGTH_SHORT).show();
        }
    }
}





    




运行结果:
android开关控件使用(一)_第1张图片

你可能感兴趣的:(Android)