ToggleButton
两种状态
·状态button
    -继承自CompoundButton
·主要属性:-Android:textOn
   -Android:textOff
·主要方法:
  -isChecked()
·主要事件

  -setOnClickListener(OnClickListener l)


xml中:
增加一个ToggleButton控件

 <ToggleButton
        android:id="@+id/btnTest"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/tv_info"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="39dp"
        android:checked="true"
        android:onClick="doClick"
        android:textOff="关闭"
        android:textOn="打开" />

MainActivity中对控件进行监听:

public void doClick(View v){
		if(btnTest.isChecked()){
			tv.setText("button被选中");
		}else{
			tv.setText("button未被选中");
		}
	}


posted on 2017-06-09 19:48  yutingliuyl  阅读(281)  评论(0)    收藏  举报