一. 类的继承结构关系图

android.widget.Button

    --- android.widget.CompoundButton

        --- android.widget.CheckBox

        --- android.widget.RadioButton

        --- android.widget.Switch

        --- android.widget.ToggleButton

二. Button 类的使用

1) 注册单击事件监听器

final Button button = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    // Perform action on click
    }
});

2) 配置 XML 的 onClick 方法

<Button
android:layout_height="wrap_content"
android:layout_width
="wrap_content"
android:text
="@string/self_destruct"
android:onClick
="doWork" />
public void doWork(View view) {
// do something...
}

3) 按钮样式


三.CompoundButton 类的使用

1) 类的声明及定义

public abstract class CompoundButton extends Button implements Checkable

2) 常用方法

1. isChecked()
2. performClick()            //Call this view's OnClickListener, if it is defined.
3. setButtonDrawable()        //Set the background to a given Drawable
4. setChecked(boolean checked)   //Changes the checked state of this button.
5. toggle()              //Change the checked state of the view to the inverse of its current state

更多相关文章

  1. 浅谈Java中Collections.sort对List排序的两种方法
  2. 箭头函数的基础使用
  3. NPM 和webpack 的基础使用
  4. Python list sort方法的具体使用
  5. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  6. python list.sort()根据多个关键字排序的方法实现
  7. Android(安卓)EditText 只能输入三行文本的实现方法
  8. 如何退出Android应用程序
  9. android http请求

随机推荐

  1. Android(安卓)Partitions Explained: boo
  2. Android(安卓)uses-permission权限
  3. Android电话录音
  4. Android简单的下拉刷新(谷歌官方)
  5. openGL 简单demo
  6. Android、iPhone手机刘海屏适配判断
  7. Android(安卓)长按setOnItemLongClickLis
  8. Android(安卓)播放资源文件视频
  9. Android中的Banner效果
  10. Android笔记(28)MVVM架构过程