当前位置: 代码迷 >> Android >> 禁用状态栏时,应用程序不会收到点击
  详细解决方案

禁用状态栏时,应用程序不会收到点击

热度:96   发布时间:2023-08-04 11:31:12.0
  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而不禁用应用程序顶部的方法?

使用自定义主题来隐藏您的状态栏。 在你的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">
  相关解决方案