View的点击泛黑显示效果
2020-01-13 本文已影响0人
WotYang
老的方法都是FrameLayout加一个foreground,这里是用自定义view去实现
public class PressedTextView extends AppCompatTextView {
public PressedTextView(Context context) {
super(context);
}
public PressedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public PressedTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (isPressed()) {
canvas.drawColor(0x33000000);
}
}
@Override
protected void dispatchSetPressed(boolean pressed) {
super.dispatchSetPressed(pressed);
invalidate();
}
}