创建系统覆盖,其中主场按钮仍然工作? [英] Creating a system overlay where the home buttons still work?

查看:137
本文介绍了创建系统覆盖,其中主场按钮仍然工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个按钮,总是在屏幕上。

  1. 按钮应该是可以点击的, 直接在按钮下的任何 不应该在preSS激活。
  2. 在活动或主屏幕运行 后面的按钮应该仍然工作, 这意味着用户应该还是 能够与家庭互动 屏幕或应用程序。
  3. 软键 按钮应该仍然工作:家里, 返回,菜单等

下面code确实#1和#2,但软按键不再起作用:

  WindowManager.LayoutParams PARAMS =新WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
        WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
        PixelFormat.TRANSLUCENT);
 

将其更改为这个禁止覆盖的点击,但#2和#3的工作:

  WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
 

最后,在这个例子中,叠加和什么是正后方它被点击:

  WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
 

我怎样才能改变这一点,以便覆盖是可以点击的,什么直属无法点击,并覆盖之外的一切工程,包括家庭按钮?

这执行所有的这方面的一个示例应用是超级管理器

更新:我发现下面允许使用home键,但仍然没有其他按钮:

  WindowManager.LayoutParams.TYPE_SYSTEM_ALERT |
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
 

解决方案
  1. 您不能或窗口类型在一起。您将创建一些随机的其他类型的。老实说,您正在使用的窗口类型真的不打算通过应用程序的使用(这就是为什么他们有系统一词在其中)。

  2. 你所说的软按键不再起作用是什么意思?它不应该是可以从停止工作在家,如果它是一个很大的问题(我想知道code要做到这一点)。其它键被输送到当前键焦点;如果你不希望被关注,使用 FLAG_NOT_FOCUSABLE

  3. 该文档这些标志应该是pretty的清楚它做什么,所以挑选你想要的标志。 FLAG_NOT_FOCUSABLE <$ C C $>,因为你不希望采取关键事件。 FLAG_NOT_TOUCH_MODAL ,因为你不希望阻止触摸事件是你的窗外。你不说你要了解你的窗口以外的presses,所以没有理由使用 FLAG_WATCH_OUTSIDE_TOUCH

I am trying to create a button that is always on the screen.

  1. The button should be clickable and anything directly under the button should not be activated on a press.
  2. The activity or home screen running behind the button should still work, meaning the user should still be able to interact with the home screen or application.
  3. The soft key buttons should still work: home, back, menu, etc

The following code does #1 and #2 but the soft key buttons no longer work:

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
        WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
        PixelFormat.TRANSLUCENT);

Changing it to this disables the overlay from clicks but #2 and #3 work:

WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,

Finally in this example the overlay and what is directly behind it gets clicked:

WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,

How can I change this so that the overlay is clickable, whats directly under it is not clickable, and everything outside of the overlay works including the home buttons?

An example application that performs all of this is Super Manager.

UPDATE: I've found that the following allows the home button to be used, but still not the other buttons:

        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT | 
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH

,

解决方案

  1. You can't OR window types together. You will create some random other type. And to be honest, the window types you are using were really not intended for use by apps (that is why they have the word "system" in them).

  2. What do you mean by "soft key buttons no longer work"? It should not be possible to stop home from working, if it is that is a big problem (I'd like to know the code to do this). The other keys are delivered to the current key focus; if you don't want to be focused, use FLAG_NOT_FOCUSABLE.

  3. The documentation for each of these flags should be pretty clear what it does, so pick the flags that do what you want. FLAG_NOT_FOCUSABLE because you don't want to take key events. FLAG_NOT_TOUCH_MODAL because you don't want to block touch events that are outside of your window. You don't say you want to find out about presses outside of your window, so there is no reason to use FLAG_WATCH_OUTSIDE_TOUCH.

这篇关于创建系统覆盖,其中主场按钮仍然工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆