zoukankan      html  css  js  c++  java
  • Android Button [ 学习笔记 一 ] 原创

    一. 类的继承结构关系图

    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
  • 相关阅读:
    DataItem 的使用[转帖]
    xmpp协议阅读总结
    smart pointer shared_from_this的使用
    std IO库, stringstream, 简看1
    const成员函数, const member function
    enum 随笔
    分隔和截断字符串, boost string algorithm library中的split和trim
    C++中异常处理
    boost::thread中的锁
    函数对象function object 以及boost::bind的一点了解
  • 原文地址:https://www.cnblogs.com/xpxpxp2046/p/2312814.html
Copyright © 2011-2022 走看看