gpt4 book ai didi

java - 即使我不点击按钮触摸监听器也会响应

转载 作者:行者123 更新时间:2023-12-01 14:20:07 24 4
gpt4 key购买 nike

嗯,我有另一个问题的示例代码,是一个“始终在顶部按钮应用程序”,并且对屏幕上的每次触摸都有响应。谁能帮我解决这个问题吗?我希望应用程序仅在我按下按钮时响应。这是代码:

public class HUD extends Service implements OnClickListener, OnTouchListener {
Button mButton;
@Override
public IBinder
onBind(Intent intent) {
return null;
}

@Override
public void onCreate() {
super.onCreate();
//mView = new HUDView(this);

mButton = new Button(this);
mButton.setText("Screenshot");
mButton.setClickable(true);
mButton.setOnTouchListener(this);


WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
params.gravity = Gravity.LEFT | Gravity.TOP;
params.setTitle("Load Average");
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mButton, params);
}

@Override
public void onDestroy() {
super.onDestroy();
if(mButton != null)
{
((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(mButton);
mButton = null;
}
}

@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(this,"Overlay button event", Toast.LENGTH_SHORT).show(); //where it seems to be the problem
return false;
}


}

谢谢你,即使你帮不了我

最佳答案

看起来是这行代码:

WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH

您可以从docs了解更多信息。 。为什么你的代码中有这一行?

关于java - 即使我不点击按钮触摸监听器也会响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17684770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com