问题描述
WindowManager manager = ((WindowManager) context.getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE));
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
manager.getDefaultDisplay().getHeight();
localLayoutParams.height = (int) (25 * context.getResources()
.getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;
view = new customViewGroup(context);
manager.addView(view, localLayoutParams);
由于顶部不可见view
我的应用顶部按钮不会收到click
事件。
您能否提出一种可以禁用status bar
而不禁用应用程序顶部的方法?
1楼
使用自定义主题来隐藏您的状态栏。 在你的styles.xml 创建一个自定义主题:
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
只需将其添加到您的 AndroidManifest.xml 中:
<application
...
...
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">