我遵循https://github.com/noln/system-alert-window-example中的代码。
并使用以下代码
private void addOverlayView(){
final WindowManager.LayoutParams params =
new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat);
params.gravity = Gravity.CENTER | Gravity.START;
params.x = 0;
params.y = 0;
FrameLayout interceptorLayout = new FrameLayout(this) {
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
// Only fire on the ACTION_DOWN event, or you'll get two events (one for _DOWN, one for _UP)
if (event.getAction() == KeyEvent.ACTION_DOWN) {
// Check if the HOME button is pressed
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
Log.v(TAG, "BACK Button Pressed");
// As we've taken action, we'll return true to prevent other apps from consuming the event as well
return true;
}
}
// Otherwise don't intercept the event
return super.dispatchKeyEvent(event);
}
};
floatyView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.floating_view, interceptorLayout);
floatyView.setOnTouchListener(this);
windowManager.addView(floatyView, params);
工作正常。但是此布局会阻止原始应用程序上的click事件。
任何人都可以帮助我找到一种用户可以在此应用框架布局下单击的方式。
答案 0 :(得分:1)
删除此行
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
更多信息click hear