我在找伪码或真码。
我的目标是在两个边界之间的任意时间显示一个模态消息框(如“保持在顶部”和“不可规避”),比如t_in_minutes_minimum和t_in_minutes_maximum,它们的内容总是相同的。
如果我不点击up,信息不应该堆积如山,而是关闭自己在一段时间后。
PS:我试了很多次。
发布于 2017-01-20 17:45:16
可以使用WindowManager api在应用程序外部创建警报窗口。
What is WindowManager in android?
代码段
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"/>
对于“自动关闭”消息,您可以使用处理程序在时间增量之后忽略。
发布于 2017-01-20 17:22:50
建立一个一致的报警经理服务类,并对alert.dialogue活动进行研究。在通过框显示消息后,请选中下面的链接
Execute function after 5 seconds in Android
并调用finish();函数关闭消息框。
https://stackoverflow.com/questions/41768957
复制相似问题