ysf*_*yln 6 android overlay back-button android-windowmanager
我有一个像Facebook聊天buble的浮动视图,但与它不同,我的叠加层有一个EditText,需要具有焦点.
这是我的浮动视图代码
//Inflate the floating view layout we created
mFloatingView = LayoutInflater.from(this).inflate(R.layout.floating_widget_layout, null);
//Add the view to the window.
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
//Specify the view position
params.gravity = Gravity.TOP | Gravity.START; //Initially view will be added to top-left corner
params.x = 0;
params.y = 100;
//Add the view to the window
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mFloatingView, params);
Run Code Online (Sandbox Code Playgroud)
它几乎是好的,但有一个问题.当我从服务创建叠加时,系统后退按钮不起作用.如果我使用FLAG_NOT_FOCUSABLE系统按钮; 家庭,最近和后面的工作如预期.我在SO做了一些研究,发现这是一个安全问题,所以我开始寻找替代解决方案,然后发现这改变了我的代码
// Wrapper for intercepting System/Hardware key events
ViewGroup wrapper = new FrameLayout(this) {
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode()==KeyEvent.KEYCODE_BACK) {
Log.v("Back", "Back Key");
return true;
}
return super.dispatchKeyEvent(event);
}
};
//Inflate the floating view layout we created
mFloatingView = LayoutInflater.from(this).inflate(R.layout.floating_widget_layout, wrapper);
//Add the view to the window.
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
//Specify the view position
params.gravity = Gravity.TOP | Gravity.START; //Initially view will be added to top-left corner
params.x = 0;
params.y = 100;
//Add the view to the window
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mWindowManager.addView(mFloatingView, params);
Run Code Online (Sandbox Code Playgroud)
现在我可以从我的浮动视图中取回按钮但是如何将此事件(反压)传递给前台应用程序(其他应用程序,而不是我的)?我找到了这个,但它没有帮助我
如果有人可以帮助我或者至少提供线索,我将不胜感激
摘要
我有一个叠加视图,它需要是可聚焦的,但是当它可以聚焦时,按下按钮不工作我怎么能解决这个问题?
小智 -1
本教程似乎有一个解决方案:https://www.geeksforgeeks.org/how-to-make-a-floating-window-application-in-android/
他们FLAG_NOT_FOCUSABLE最初进行设置,以便覆盖层不会干扰系统后退功能等。他们在 EditText 上设置 onTouch 侦听器,并将标志更新到FLAG_NOT_TOUCH_MODAL此时,以便可以输入文本。
| 归档时间: |
|
| 查看次数: |
782 次 |
| 最近记录: |