stateListDrawable是Drawable资源的一种,可以根据不同的状态,设置不同的图片效果,关键节点。,我们只需要将Button的background属性设置为该drawable资源即可轻松实现,按下按键时候不同的按键颜色或者背景
    android:state_focused=”true” 是否获得焦点
    android:state_pressed=”true”控件是否被按下
    android:state_enabled=”true”控件是否可用
    android:state_selected=”true”控件是否被选择,针对有滚轮的情况
    android:state_checked=”true”控件是否被勾选
    android:state_checkable=”true”控件可否被勾选
    android:state_window_focused=”true”是否获得窗口焦点
    android:state_active=”true”控件是否处于活动状态
    android:state_single=”true”控件包含多个子控件时,确定是否只显示一个子控件
    android:state_first=”true”控件包含多个子空间时,确定第一个子控件是否有处于显示状态
    android:state_middle=”true”控件包含多个子控件时,确定中间一个子控件是否处于显示状态
    android:state_last=”true”控件包含多个子控件时,确定最后一个子控件是否处于显示状态
    代码示例

    <?xml version=”1.0” encoding=”utf-8”?>
    android:layout_height=”match_parent”
    android:orientation=”vertical”
    xmlns:android=”http://schemas.android.com/apk/res/android">

    1. <Button<br /> android:text="按钮"<br /> android:background="@drawable/btn_selector"<br /> android:layout_width="200dp"<br /> android:layout_height="100dp"<br /> android:foreground="#ff00ff00"<br /> android:backgroundTint="@color/btn_color_selector"<br /> /><br /></LinearLayout>

    <?xml version=”1.0” encoding=”utf-8”?>



    <?xml version=”1.0” encoding=”utf-8”?>



    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView btn = findViewById(R.id.btn);
    //点击事件
    btn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
    Log.e(TAG,”onClick: “);
    }
    });
    //点击长按事件
    btn.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View view) {
    Log.e(TAG,”onLongClick: “);
    return false;
    }
    });
    //触摸事件
    btn.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
    Log.e(TAG,”onTouch: “);
    return false;
    }
    });

    }