【发布时间】:2016-05-23 13:51:09
【问题描述】:
我正在开发一个 android 应用程序,在该应用程序中我对我的窗口使用自定义视图。我有以下代码:-
private void systemOverlayFullScreen()
{
WindowManager manager = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE));
//manager.removeView(view);
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
// changed to alerts or overlay from system_error
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
// set width and height of overlay originally -1
localLayoutParams.width = -1;
// changed gravity to bottom so as to hide the stop the home button press; originally -1
localLayoutParams.height = -1;
localLayoutParams.y = -getNavigationBarHeight();
localLayoutParams.x = 0;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
// you can change it to transparent
//localLayoutParams.format = PixelFormat.TRANSLUCENT;
localLayoutParams.alpha = 0.3f;
CustomViewGroup view = new CustomViewGroup(this);
manager.addView(view, localLayoutParams);
}
当我单击主页按钮然后再次重新启动我的应用程序时,之前添加的自定义视图仍然存在。我想在应用重新启动时将其删除。
我已经尝试过:-
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
if(view.getWindowToken() != null)
{
Toast.makeText(getApplicationContext(), "View present", Toast.LENGTH_SHORT).show();
WindowManager manager = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE));
manager.removeView(view);
}
else
{
Toast.makeText(getApplicationContext(), "View not present", Toast.LENGTH_SHORT).show();
}
}
但这不起作用。
谁能告诉我如何在应用启动时动态删除视图?
【问题讨论】:
标签: android android-custom-view android-windowmanager