次のコードを使用して、すべてのアプリケーションとウィンドウの上に表示されるビューを作成しました。
//These three are our main components.
WindowManager wm;
LinearLayout ll;
WindowManager.LayoutParams ll_lp;
//Just a sample layout parameters.
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
ll_lp = new WindowManager.LayoutParams();
ll_lp.format = PixelFormat.TRANSLUCENT;
ll_lp.height = WindowManager.LayoutParams.FILL_PARENT;
ll_lp.width = WindowManager.LayoutParams.FILL_PARENT;
ll_lp.gravity = Gravity.CLIP_HORIZONTAL | Gravity.TOP;
//This one is necessary.
ll_lp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
//Play around with these two.
ll_lp.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
ll_lp.flags = ll_lp.flags | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
//This is our main layout.
ll = new LinearLayout(this);
ll.setBackgroundColor(android.graphics.Color.argb(50, 255, 255, 255));
ll.setHapticFeedbackEnabled(true);
ll.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(getApplicationContext(), "TOUCHED", Toast.LENGTH_SHORT).show();
return false;
}
});
//And finally we add what we created to the screen.
wm.addView(ll, ll_lp);
FLAG_NOT_TOUCHABLEが設定されているため、ビューのみが表示され、タッチイベントは受信されません。ビューの背後にあるアプリケーションは、すべてのタッチイベントを受け取ります。ただし、フラグを設定しないと、ビューのみがタッチを受信し、その背後にあるアプリケーションはタッチを受信しません。
ビューとその背後にあるアプリケーションの両方がタッチを受け取る方法はありますか?falseを返そうとしましたが、それでも同じです。
どんな助けでも大歓迎です!