禁用状态栏时,该应用无法获得点击

时间:2015-10-25 10:01:12

标签: android

  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);

我的应用程序顶部按钮因顶部不可见click而无法接收view个事件。你可以建议一种我可以禁用status bar的方法,而不会禁用应用程序的顶端吗?

1 个答案:

答案 0 :(得分:0)

使用自定义主题隐藏状态栏。在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">