内容转自:http://blog.csdn.net/wanglj0925/article/details/8840807
1.view显示到window最顶层方法
因为很多厂商定制各自的android系统,不同的type在不同的手机上表现不同。根据自己的需要设置不同的type类型。
/**
*
* @Method: showTopWindow
* @Description: 显示最顶层view
*/
public void showTopWindow(View view) {
//window管理器
WindowManager windowManager = (WindowManager) getApplicationContext()
.getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
| WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
// params.flags = LayoutParams.FLAG_NOT_FOCUSABLE;
//设置全屏显示 可以根据自己需要设置大小
params.width = WindowManager.LayoutParams.FILL_PARENT;
params.height = WindowManager.LayoutParams.FILL_PARENT;
//设置显示初始位置 屏幕左上角为原点
params.x = 0;
params.y = 0;
// topWindow显示到最顶部
windowManager.addView(view, params);
}
2.清除view方法
/**
*
* @Method: clearTopWindow
* @Description: 移除最顶层view
*/
public void clearTopWindow(View view) {
if (view != null && view.isShown()) {
WindowManager windowManager = (WindowManager) getApplicationContext()
.getSystemService(WINDOW_SERVICE);
windowManager.removeView(view);
}
}
加权限: <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
更多信息参考:http://blog.csdn.net/shichaosong/article/details/8213016