-1
我正在使用自定義視圖到我的窗口的android應用程序。我有以下的代碼來做到這一點: -應用程序重新啓動時刪除自定義視圖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();
}
}
但這不列入工作。
誰能告訴我如何在應用程序啓動時動態刪除視圖?
感謝您的回覆,但我打電話給我的方法添加視圖只從onPause活動,當活動重新啓動時,我想刪除視圖..因此,我把它放在onRestart() –
我誤會了,因爲你說重新啓動應用程序。但我注意到你的方法你有 CustomViewGroup視圖=新的CustomViewGroup(this); manager.addView(view,localLayoutParams); 多數民衆贊成在該方法的本地對象,所以你想在onRestart方法中刪除什麼視圖? – Aaron
多數民衆贊成在同一個對象/視圖我想刪除..讓我評論一下,使視圖全球和檢查..謝謝指出 –