最后我作为@Matthieu的基本答案,让它以这样的方式工作。 我决定公布我的答案,因为我花了30分钟才能理解为什么会出错。

XML

.TouchBlackHoleView android:id="@+id/blackHole" android:layout_width="match_parent" android:layout_height="match_parent" />

公共类TouchBlackHoleView扩展了View {private boolean touchDisable = false;

public TouchBlackHoleView(Context context) { super(context); } public TouchBlackHoleView(Context context, AttributeSet attrs) { super(context, attrs); } public TouchBlackHoleView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override public boolean onTouchEvent(MotionEvent event) { return touchDisable; } public void disableTouch(boolean value){ touchDisable = value; } }

运用

blackHole = (TouchBlackHoleView) findViewById(R.id.blackHole); blackHole.disableTouch(true);

请享用

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐