0

我想在每个窗口的顶部建立一个视图。

我找到了这段代码:

bt = new Button(getApplicationContext());
LayoutParams param = new LayoutParams();
param.flags = LayoutParams.FLAG_NOT_FOCUSABLE;
param.format = PixelFormat.RGBA_8888;
param.type = LayoutParams.TYPE_SYSTEM_ALERT;
param.gravity = Gravity.TOP | Gravity.LEFT;
param.width = 40;
param.height = 40;
wmgr = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
wmgr.addView(bt, param);

并在manifest.xml

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

视图已构建,但是当我按下主页按钮时,除了状态栏之外我什么都看不到。

怎么了?请帮我。

4

1 回答 1

0

改变

wmgr = (WindowManager) getSystemService(Context.WINDOW_SERVICE); 

wmgr = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
于 2011-12-12T18:28:43.787 回答