我想在每个窗口的顶部建立一个视图。
我找到了这段代码:
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"/>
视图已构建,但是当我按下主页按钮时,除了状态栏之外我什么都看不到。
怎么了?请帮我。