日期:2014-05-17  浏览次数:20800 次

将一个视窗(windows)盖在整个Application的最上面

有这样的需求: 将一个窗口放在Appplication的所有Activity的最上面,该如何做到呢? ?

答案是:?

?private ImageView waitView;

private final void showWaiting() {

?try {

WindowManager.LayoutParams lp = null;

lp = new WindowManager.LayoutParams(

ViewGroup.LayoutParams.WRAP_CONTENT,

ViewGroup.LayoutParams.WRAP_CONTENT,

WindowManager.LayoutParams.TYPE_TOAST ,

WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE

| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE

| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,

PixelFormat.TRANSLUCENT

| WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW) ;

WindowManager mWindowManager = (WindowManager) G.appInstance

.getSystemService(Context.WINDOW_SERVICE);

if (waitView == null) {

LayoutInflater inflate = (LayoutInflater) G.appInstance

.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

waitView = (ImageView) inflate.inflate(R.layout.waiting_layout,

null);

}

mWindowManager.addView(waitView, lp);

} catch (Throwable e) {

}

}

注意粗体部分的代码:?

1. 要将window的类型配置成Type_toast。?

2.G.appInstance 上下文需要使用Application的context.

1 楼 gqdy365 2011-04-18  
实现了什么效果?不太懂你的: 将一个窗口放在Appplication的所有Activity的最上面