ToggleButton
两种状态
·状态按钮
-继承自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("按钮被选中");}else{tv.setText("按钮未被选中");}}


更多相关文章

  1. Android控件及API说明(二)
  2. Android添加圆角渐变色按钮
  3. 一起学android之底部菜单TabHost的实现(9)
  4. Android——按钮的事件监听
  5. android之button
  6. Android精讲--界面编程3
  7. Android(安卓)基本Dialog和自定义Dialog
  8. Android(安卓)基本Dialog和自定义Dialog
  9. Android(安卓)Layout XML属性

随机推荐

  1. 移动互联网盈利知识汇总
  2. android webview 底层实现的逻辑
  3. android,进入页面textview默认获得焦点问
  4. android EditText 全面阐述
  5. How to decompile .dex file on Android
  6. android更新
  7. Android(安卓)Camera使用小结
  8. 解决 Android(安卓)SDK下载和更新失败“C
  9. Android引用资源(resources) vs 引用样式属
  10. android Log.isLoggable步骤的使用