2020-10-27

图片点击变暗效果

xml中直接调用<ClickImageView />

public class ClickImageView extends AppCompatImageView {

    public ClickImageView(@NonNull Context context) {
        super(context);
    }

    public ClickImageView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ClickImageView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                this.setColorFilter(0x99000000);
                return true;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                this.setColorFilter(null);
                break;
        }
        return super.onTouchEvent(event);
    }

}

 

textview选中效果

// textview选中
tvDanger.setSelected(true);
// textview未选中
tvDanger.setSelected(false);

 

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页