WindowManager.addView软键或导航栏的ontop(覆盖) [英] WindowManager.addView ontop(overlay) of soft key OR nav bar
问题描述
今天,我看到一个应用程序覆盖了整个屏幕,包括导航栏(或具有返回,首页等功能的软键).是chainfire的CF.Lumen(需要android 4.4 +).
I saw an app that overlays whole screen including nav bar (or soft-key that has back, home, etc.) today. it's CF.Lumen(requires android 4.4+) by chainfire.
我只是想起这在一般方法上是不可能的,所以有很多答案告诉我.因此,我从Lumens apk(对不起的链火)中查找了smali代码,发现0x7d6
作为类型说明符,即TYPE_SYSTEM_OVERLAY
.
通常,这会使视图覆盖在锁定屏幕的顶部.看起来不错,但是不会覆盖导航栏区域.即使在锁定屏幕上
我确实将MATCH_PARENT
替换为9999
,但是它仍然不会覆盖导航栏区域.
I just remembered this is NOT POSSIBLE on general approach and many SO answers told me. So I looked down smali codes from Lumens apk(sorry chainfire), found 0x7d6
as type specifier, which is TYPE_SYSTEM_OVERLAY
.
In general, this makes a view overlays on top of lock screen. It looks good however it won't overlays nav bar area. even on lock screen.
I did replacing MATCH_PARENT
to 9999
but it still won't overlays nav bar area.
我看了看Android的源代码,发现有趣的是它有更多未记录的类型.
I looked down the source code of Android, found interesting that has more types undocumented.
FIRST_SYSTEM_WINDOW = 2000;
FIRST_SYSTEM_WINDOW = 2000;
TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW + 19;
TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19;
TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW + 21;
TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21;
我将这些应用到了我的应用中,但是当崩溃时,提示权限被拒绝.它需要INTERNAL_SYSTEM_WINDOW
或比SYSTEM_ALERT_WINDOW
更多未记录的内容.这些权限仅授予系统应用程序.
I applied these to my app but got crashe says permission denied. It requires INTERNAL_SYSTEM_WINDOW
OR something more undocumented than SYSTEM_ALERT_WINDOW
. those permissions are granted for system apps only.
这是我的代码,用于添加除导航栏区域之外的整个屏幕的视图.
here's my code to add a view fills whole screen except nav bar area.
我应该怎么做才能完成它(使覆盖包括导航栏区域)
What should I do to acomplish it?(make overlay including nav bar area)
final WindowManager.LayoutParams paramsRL = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
PixelFormat.TRANSLUCENT);
windowManager.addView(view_floating, paramsRL);
推荐答案
下面是一个可行的小示例:
Here's a small example which works:
FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setBackgroundColor(Color.BLACK);
frameLayout.setAlpha(0.5f);
windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
| WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
PixelFormat.TRANSLUCENT);
//make sure height includes the nav bar size (get the dimension of whole screen)
params.height = screenHeight;
params.width = screenWidth;
windowManager.addView(frameLayout, params);
//add your view to this frameLayout
frameLayout.addView(....);
这里的三个关键要素是:
Three key things here are:
-
TYPE_SYSTEM_OVERLAY(或任何类似类型)可以在整个屏幕上显示内容.
TYPE_SYSTEM_OVERLAY (or any similar types) which can show content over the whole screen.
FLAG_LAYOUT_NO_LIMITS,使我们可以超过允许的正常大小.
FLAG_LAYOUT_NO_LIMITS which allows us to go over the normal size allowed.
设置软键后面需要覆盖的额外高度.主要问题是,当我们将参数设置为match_parent时,它将设置为屏幕的高度减去我猜想的导航栏.设置额外的高度可以解决问题.
Setting the extra height required to be covered behind soft keys. The main problem was when we set the parameters to match_parent, it sets to the height of screen minus the nav bar I suppose. Setting the extra height solves the issue.
这篇关于WindowManager.addView软键或导航栏的ontop(覆盖)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!