按钮按下、长按、松开三种状态:
切换背景图片时使用
setOnClickListener:按下
setOnLongClickListener:长按
bt1.setOnTouchListener(new View.OnTouchListener()setOnTouchListener:松开
{
@Override
public boolean onTouch(View view, MotionEvent motionEvent)
{
//按下操作
if(motionEvent.getAction()==MotionEvent.ACTION_DOWN)
{
}
//抬起操作
if(motionEvent.getAction()==MotionEvent.ACTION_UP)
{
}
//移动操作
if(motionEvent.getAction()==MotionEvent.ACTION_MOVE){
}
return false;
}
});
设置按钮边框、背景
GradientDrawable drawable = new GradientDrawable();
drawable.setShape(GradientDrawable.RECTANGLE); // 画框
drawable.setStroke(1, Color.BLACK); // 边框粗细及颜色
drawable.setColor(Color.YELLOW);
bt1.setBackgroundDrawable(drawable);
设置按钮字体背景
bt1.setBackgroundColor(0xFF62BCFA);