在纯安卓原生中隐藏导航栏 [英] Hiding the navigation bar in pure android native

查看:279
本文介绍了在纯安卓原生中隐藏导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过关于通过java隐藏android应用程序导航栏的文章和文章.但是,我想知道的是如何通过纯 android c++ 本机活动应用程序为全屏应用程序(游戏)(根本没有 JAVA!)删除导航栏.android manifest 中的全屏可以隐藏顶部栏,但导航栏保持可见.

I've seen articles and articles on hiding the navigation bar for android application through java. However, what I would like to know, is how do I remove the navigation bar through a pure android c++ native-activity application for a full-screen application(game)(NO JAVA AT ALL!). Full-screen from the android manifest works at hiding the top bar, but the navigation bar stays visible.

这是我想删除的导航栏.

我在没有运气的情况下搜索过书籍,没有关于本地活动的实际文档,谷歌搜索没有任何结果.只有一些头文件中的注释是微小的注释,甚至没有帮助.似乎关于纯c++ android应用程序的话题是一个黑点,但市场上出现的很多游戏都是用c++编写的.

I've searched through books with no luck, there's is no actual documentation for native-activity and google searches result in nothing. There is only the comments inside some of the header files which are tiny comments that don't even help. It seems the topic regarding pure c++ android applications is a black spot yet a lot of games that are coming out on the market are written in c++.

我也试过设置:

AConfiguration_setNavHidden(m_app->config, ACONFIGURATION_NAVHIDDEN_YES);

但它似乎什么都不做,实际上所有的AConfiguratin_setXXX似乎什么都不做.也许我在错误的地方调用它?创建窗口后,我一直在 APP_CMD_INIT_WINDOW 期间调用它.我应该在哪里调用这个函数?

But it seems to do nothing, in fact all the AConfiguratin_setXXX seem to do nothing. Perhaps I'm calling it in the wrong place? I've been calling it during APP_CMD_INIT_WINDOW after creating the window. Where should I be calling this function?

推荐答案

那么!如果有人好奇,我确实通过翻阅微软的茶壶示例之一得出了答案.这就是我想出的:

So! If anyone is curious, I did come up with an answer from rummaging through one of Microsoft's teapot examples. And this is what I came up with:

public class NameOfActivity extends NativeActivity {

void setImmersiveSticky() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_main);

    int SDK_INT = android.os.Build.VERSION.SDK_INT;
    if (SDK_INT >= 19) {
        setImmersiveSticky();

        View decorView = getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener
                (new View.OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                        setImmersiveSticky();
                    }
                });
    }
    super.onCreate(savedInstanceState);
}

@Override
protected void onResume() {
    //Hide toolbar
    int SDK_INT = android.os.Build.VERSION.SDK_INT;
    if (SDK_INT >= 11 && SDK_INT < 14) {
        getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
    } else if (SDK_INT >= 14 && SDK_INT < 19) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE);
    } else if (SDK_INT >= 19) {
        setImmersiveSticky();
    }
    super.onResume();
}

}

纯c++的android开发还是用java,从android SDK目录里面的源码中获取.您可以做的是通过一些额外的调整来扩展 NativeActivity.在清单中,您所要做的就是:

The pure c++ android development still uses java, it gets it from the source inside the android SDK directory. What you can do is extend the NativeActivity with a few additional tweaks. Inside the manifest all you have to do is:

    android:hasCode="true"

然后最重要的部分是更改活动名称

and then the most importan part is to change the activity name from

        android:name="android.app.NativeActivity"

        android:name="com.example.package.NameOfActivity"

它仍然会像常规的本机 Activity 一样调用 android main 并对其进行设置,但现在它为您提供了一个完全全屏的屏幕.我希望这可以帮助那里的人.我花了几天的时间寻找答案,这就是我能想出的!

It will still call the android main and set it up just like a regular native activity, but now it gives you a completely full-screen. I hope this helps someone out there. It took me a days of searching for answers, and this is what I could come up with!

祝你好运!

这篇关于在纯安卓原生中隐藏导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆