首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在应用程序外部显示一条模态消息,并在一段时间后关闭它自己。

在应用程序外部显示一条模态消息,并在一段时间后关闭它自己。
EN

Stack Overflow用户
提问于 2017-01-20 17:09:40
回答 2查看 80关注 0票数 0

我在找伪码或真码。

我的目标是在两个边界之间的任意时间显示一个模态消息框(如“保持在顶部”和“不可规避”),比如t_in_minutes_minimumt_in_minutes_maximum,它们的内容总是相同的。

如果我不点击up,信息不应该堆积如山,而是关闭自己在一段时间后。

  1. 有办法和报警器联系吗?
  2. 如何在应用程序之外显示模态消息?
  3. 一段时间后,我怎样才能让我的信息在没有敲击的情况下自动关闭呢?

PS:我试了很多次。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-01-20 17:45:16

可以使用WindowManager api在应用程序外部创建警报窗口。

What is WindowManager in android?

代码段

代码语言:javascript
复制
WindowManager.LayoutParams p = new WindowManager.LayoutParams(
// Shrink the window to wrap the content rather than filling the screen 
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
// Display it on top of other application windows, but only for the current user
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
// Don't let it grab the input focus
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
// Make the underlying application window visible through any transparent parts
PixelFormat.TRANSLUCENT);
// Define the position of the window within the screen
p.gravity = Gravity.TOP | Gravity.RIGHT;
p.x = 0;
p.y = 100;

WindowManager windowManager = (WindowManager)getSystemService(WINDOW_SERVICE);
windowManager.addView(myView, p);

将此添加到清单中

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

对于“自动关闭”消息,您可以使用处理程序在时间增量之后忽略。

票数 1
EN

Stack Overflow用户

发布于 2017-01-20 17:22:50

建立一个一致的报警经理服务类,并对alert.dialogue活动进行研究。在通过框显示消息后,请选中下面的链接

Execute function after 5 seconds in Android

并调用finish();函数关闭消息框。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41768957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档