【发布时间】:2016-03-23 21:33:48
【问题描述】:
当我单击屏幕上的按钮时,我想关闭我的应用程序。
public WindowManager winManager;
public RelativeLayout wrapperView;
public Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams( WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
this.winManager = ((WindowManager)getApplicationContext().getSystemService(WINDOW_SERVICE));
this.wrapperView = new RelativeLayout(getBaseContext());
getWindow().setAttributes(localLayoutParams);
View.inflate(this, R.layout.activity_main, this.wrapperView);
this.winManager.addView(this.wrapperView, localLayoutParams);
button1 = (Button)wrapperView.findViewById(R.id.button1);
button1.setOnClickListener(mButton1_OnClickListener);
}
View.OnClickListener mButton1_OnClickListener = new View.OnClickListener() {
public void onClick(final View v){
winManager.removeView(wrapperView);
wrapperView.removeAllViews();
finish();
}
};
我做了这个活动,但是当我点击按钮时,应用程序仍然出现在最近的应用程序菜单中,我不知道为什么。
【问题讨论】:
标签: android