Haxe: How can I make the android menu bar stay hidden

倖福魔咒の 提交于 2020-01-06 05:08:05

问题


Im developing an app using haxe / openfl, with the flashdevelop ide. The default setup for a new project comes with the correctly configured android manifest so that the android menu bars dont show up. However when I touch anywhere on the device they pop up. How can I prevent this from happening.

Okay, so I found the the template GameActivity.java file that the system was using to generate the apps code and modified it to include:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    if(hasFocus) {
        hideSystemUi();
    }
}

private void hideSystemUi() {
    View decorView = this.getWindow().getDecorView();

    if (Float.valueOf(android.os.Build.VERSION.RELEASE.substring(0, 3))>=4.4){

    decorView.setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_FULLSCREEN
        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    }
    else
    {
    decorView.setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        | View.SYSTEM_UI_FLAG_FULLSCREEN);
    }
}

Now its all working nicely. Will post this as answer when the 8 hours are up


回答1:


You're after Immersive Sticky Mode that hides manu bars and software buttons on Android 4.4+. You've got it correct with setting flags via View.setSystemUiVisibility method.

However, one thing to keep in mind is that in Immersive Sticky Mode the menu bars will reappear if you use hardware volume buttons. To prevent it, you'll have to use a delayed Runnable that sets Immersive Sticky Mode again. You're using OpenFL so below is a set of modifications I use in my GameActivity:

private void setSystemUiVisibility() {
    ::if WIN_FULLSCREEN::
    ::if (ANDROID_TARGET_SDK_VERSION >= 19)::
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
            View.SYSTEM_UI_FLAG_FULLSCREEN |
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        );
    }
    ::elseif (ANDROID_TARGET_SDK_VERSION >= 16)::
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
            View.SYSTEM_UI_FLAG_LOW_PROFILE |
            View.SYSTEM_UI_FLAG_FULLSCREEN
        );
    }
    ::end::
    ::end::
}

private final Runnable activateImmersiveMode = new Runnable() {
    @Override
    public void run() {
        setSystemUiVisibility();
    }
};

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        mHandler.postDelayed(activateImmersiveMode, 500);
    }
    return super.onKeyDown(keyCode, event);
}

@Override protected void onResume() {
    super.onResume();
    setSystemUiVisibility();
    // rest of onResume()
}

@Override protected void onStart() {
    super.onStart();
    setSystemUiVisibility();
    // rest of onStart()
}


来源:https://stackoverflow.com/questions/24539709/haxe-how-can-i-make-the-android-menu-bar-stay-hidden

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!