沉浸模式Android Studio [英] Immersive Mode Android Studio

查看:112
本文介绍了沉浸模式Android Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我制作的游戏以沉浸式模式运行,但是android studio无法识别标志沉浸式模式,因为我将最低API设置为16,并且我知道沉浸式模式仅在KitKat中添加了,稍后的.有什么方法可以让我的应用程序在不改变最低API的情况下以沉浸式模式运行?

I want the game that I'm making to run in immersive mode, but android studio doesn't recognize the flag immersive mode because I set my minimum API to 16, and I know immersive mode was added only in KitKat which is later on. Is there any way to have my app run in immersive mode without changing my minimum API?

推荐答案

是的,是可能的,但是这种沉浸式模式仅适用于具有KitKat和更高版本的设备.在您这边,这很奇怪,事实是,基于您的话语,您甚至无法获得像这样的标志:

Yes, it is possible, but of course this immersive mode will be only working on devices with KitKat and higher. This, what is weird on your side, is fact, that basing on your words, you cannot even get these flags like this:

View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;

(或其中的一部分).如果是这种方式,则说明您的compileSdkVersion低于实际值.一开始,我建议您将compileSdkVersion更新为22(同时将targetSdkVersion也更新为22)(这两种方法都可以在build.gradle中找到)

(or part of them). If it is this way, then it is looking, that your compileSdkVersion is lower, than it should be. On start I would advise you to update compileSdkVersion to 22 (and also make targetSdkVersion also 22) (both things you will find in build.gradle)

当您执行此操作时,如果您想在沉浸式添加条件下使用这些标志,请如下所示:

When you will do this, and you would like to use these flags please in places, where you want to use immersive mode add conditions, that will be looking like this:

if (Build.VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
    int UI_OPTIONS = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
    getWindow().getDecorView().setSystemUiVisibility(UI_OPTIONS);
}

那么它在老版本的操作系统上就不会混乱.

Then it should not mess on older OS.

(更新:第二个代码块已更新)

(UPDATE: 2nd block of code was updated)

这篇关于沉浸模式Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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