如何浮动视图添加到Android窗口管理器,并听取系统/硬件后退按钮事件 [英] How to add a floating view to Android Window manager and listen to System/Hardware back button events

查看:285
本文介绍了如何浮动视图添加到Android窗口管理器,并听取系统/硬件后退按钮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有显示在窗口管理器(使用WINDOW_TYPE_ALERT许可)浮动视图的服务。我能够显示并执行操作。但是,我有两个具体的问题:

I have a service which displays a floating view on the window manager (using WINDOW_TYPE_ALERT permission). I'm able to display it and perform actions. But, I have two specific questions:

  1. 关于浮动视图的实施
  2. 怎么听系统后退按钮事件,使我可以辞退的看法。

执行:

在清单中,我添加权限:

In the manifest I added permissions for:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

我有一个广播接收器,将监听报警事件。在接收的情况下,我开始显示浮动视图的服务。以下是code我用来创建视图。

I have a broadcast receiver which will listen for Alarm events. Upon receiving the event, I'm starting a service to display the floating view. The following is the code I'm using to create the view.

LayoutParams layOutParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                PixelFormat.TRANSLUCENT);

每当用户执行对视图的任何行动,我除去窗口管理器视图和查杀服务。

Whenever a user performs any action on the view, I'm removing the view from window manager and killing the service.

我想知道的是 - 如果这是正确的方式来处理这个问题还是有什么更好的办法来做到这一点?而且,我应该改变的LayoutParams或让他们作为是?

What I would like to know is - if this is the right way to approach the problem or are there any better ways to do it? And, should I make changes to the LayoutParams or keep them as is?

其次,我也想关闭此浮动看法时,有系统备份/硬件BACK按钮preSS事件。如何做到这一点的任何指针将是有益的。

Secondly, I would also like to dismiss this floating view when there is SYSTEM BACK/HARDWARE BACK button press event. Any pointers on how to do this would be helpful.

附加浮动视图的屏幕截图为了更好的理解:

Attaching a screenshot of the floating view for better understanding:

推荐答案

看一看出色的图书馆,这是很好的处理浮动窗口,现在看来,这还没有处理回preSS事件,联系开发者可能会有所帮助。

Have a look at Standout Library , which is good for handling floating windows , it seems it is also not handling back press event , contacting developer might help.

和另一种方式是,你可以尝试用半透明背景/主题开放活动取得的Any.do和背部preSS事件浮动窗口中使用的类似的效果可处理

And one more way is you can try opening activity with semi transparent background/theme to get the similar effect used in floating window in Any.do and backpress event can be handled

这篇关于如何浮动视图添加到Android窗口管理器,并听取系统/硬件后退按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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