我正在编写一个应用程序,在弹出窗口中显示未接来电和未读短信。它还具有提醒功能(关闭弹出窗口并在指定时间后打开它)。它类似于any.do的弹出窗口。
我能够使用 WindowManger 创建这样一个窗口,但由于某些我到目前为止不明白的原因,弹出窗口在一段时间后消失(尽管它应该打开,直到用户关闭它,或单击提醒按钮)这可能需要几个小时)。
这就是我创建现有弹出窗口的方式
windowManager = (WindowManager) context.getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE);
this.inflater = LayoutInflater.from(context);
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
+ WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
+ WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.BOTTOM;
vgPopupWindow = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.popup_mainwindow, null);
vgPopupContent = (ViewFlipper) vgPopupWindow.findViewById(R.id.popup_content);
vgPopupAreaContent = (ViewGroup) vgPopupWindow.findViewById(R.id.popup_area_content);
vgPopupAreaActions = (ViewGroup) vgPopupWindow.findViewById(R.id.popup_area_actions);
vgPopupTabs = (LinearLayout) vgPopupWindow.findViewById(R.id.popup_tabs);
vgPopupHeader = (LinearLayout) vgPopupWindow.findViewById(R.id.popup_main_header);
windowManager.addView(vgPopupWindow, params);
因为我不确定 WindowManager 是否真的是正确的方法,所以我也尝试对具有以下样式的活动执行相同的操作
<style name="PopupWindow" parent="CustomTheme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowIsTranslucent">true</item>
它现在看起来就像 WindowManager 版本,但有一个问题:我无法访问它下面的应用程序的窗口,因为窗口的半透明部分看起来很完美,但阻止了下面窗口的任何单击事件,以便我可以不要滚动它或用它做任何事情。就像在any.do中一样,我只想显示该窗口,但不阻止在打开弹出窗口时在下面的窗口上工作的任何可能性。
编辑:我想看到底部的弹出窗口,覆盖窗口的 30%,但能够同时滚动其下方的窗口(并对其执行单击事件)。
所以我的问题是:
- WindowManager 是创建此弹出窗口的正确方法吗?
- 如果是,为什么它有时会消失?我该如何预防?
- 如果不是,我如何创建一个行为类似于我使用 WindowManager 创建的窗口的活动?
- 或者两种方法都错了?在这种情况下;什么是正确的方法?