Reputation: 53
I'm having a problem with focus when using a floating window. My current code is:
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams parameters = new WindowManager.LayoutParams(
200, 200, WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
parameters.gravity = Gravity.CENTER;
RelativeLayout layoutView = new RelativeLayout(this);
...
windowManager.addView(layoutView, parameters);
The problem is that with this code only the floating window is focusable. I've tried changing the flags, but always either only the floating window, or the background application is focusable (so a keyboard will appear when I click an EditText
.
I want both the floating window and the background application be able to show a softkeyboard on an EditText
click.
Upvotes: 0
Views: 1027
Reputation: 11
You can try like below:
this.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_OUTSIDE) {
updateLayoutParamFlag(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
}
return@setOnTouchListener false
}
mEditText.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
updateLayoutParamFlag(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH)
}
return@setOnTouchListener false
}
fun updateLayoutParamFlag(flags: Int) {
if (mlayoutParams.flags != flags) {
mlayoutParams.flags = flags
mWindowManager.updateViewLayout(this, mlayoutParams)
}
}
Upvotes: 1
Reputation: 53
Nevermind. I used a library called StandOut (http://pingpongboss.github.io/StandOut/). It somehow manages to do the above thing. I looked into the source code, but I couldn't really figure out what it was doing to make this work, so I just rewrote part of my project to make it compatible with this library
Upvotes: 0