使用 Cordova 全屏制作 Android 应用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24302251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:00:00  来源:igfitidea点击:

Making an Android app fullscreen with Cordova

androidcordova

提问by user2406993

I'm a newcomer to Cordova, and am trying to make an app that appears full screen (hiding the taskbar at the bottom of Android).

我是 Cordova 的新手,正在尝试制作一个全屏显示的应用程序(隐藏 Android 底部的任务栏)。

I have looked online and there seem to be two different techniques.... I have tried adding

我在网上看了一下,似乎有两种不同的技术......我尝试添加

<preference name="Fullscreen" value="true" /> to my config.xml

so that it reads

所以它读

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <preference name="loglevel" value="DEBUG" />
    <preference name="AndroidLaunchMode" value="singleTop" />
    <feature name="App">
        <param name="android-package" value="org.apache.cordova.App" />
    </feature>
    <name>HelloCordova</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="[email protected]" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <preference name="Fullscreen" value="true" />
    <preference name="WebViewBounce" value="true" />
    <preference name="Orientation" value="landscape" />
    <preference name="HideKeyboardFormAccessoryBar" value="true" />
</widget>

The status bar still remains at the bottom (although the app does fix at landscape). I have also tried the other advice which involves adding lines to hellocordova.java. This imports android.view.WindowManager; and then adds lines after loading index.html:

状态栏仍然保留在底部(尽管该应用程序确实在横向上进行了修复)。我还尝试了其他建议,包括向 hellocordova.java 添加行。这将导入 android.view.WindowManager; 然后在加载 index.html 后添加行:

(WindowManager.LayoutParams.FLAG_FULLSCREEN,                   WindowManager.LayoutParams.FLAG_FULLSCREEN WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

This method stops the app from compiling with cordova build android.

此方法会阻止应用程序使用 cordova build android 进行编译。

Any tips of where I can be looking.

我可以在哪里寻找的任何提示。

I'm using Android 4.1.1

我使用的是安卓 4.1.1

回答by paul

Unfortunately the Plugin didn't work for me, so I managed it with these steps:

不幸的是,该插件对我不起作用,所以我通过以下步骤进行了管理:

Add the Fullscreen preference in your config.xmlfile:

在您的config.xml文件中添加全屏首选项:

<preference name="Fullscreen" value="true" />

Find the AndroidManifest.xmlin platforms/android/and add the Fullscreen Theme

查找AndroidManifest.xmlplatforms/android/,并添加全屏主题

<manifest ...>
    <application ...>
        <activity ... android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">

Finally, and this was the harder step, use the Immersive Full-Screen Mode. The only way I got it to work was directly extending the CordovaApp.javafile in plattforms/android/src/com/example/hello/

最后,这是更难的一步,使用沉浸式全屏模式。我让它工作的唯一方法是直接将CordovaApp.java文件扩展到plattforms/android/src/com/example/hello/

...
import android.view.View;

//Cordova onCreate function....
//public void onCreate()
//...    

//this is the important thing:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
  super.onWindowFocusChanged(hasFocus);
  View decorView = getWindow().getDecorView();
  if(hasFocus) {
        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);
    }
}

I am not an Java Developer (jet) so I can't explain in detail what happend, but it seems to work. Keep in mind that Cordova creates the platforms/androidfolder, so its possible that it will be overwritten by some actions.

我不是 Java 开发人员 (jet),所以我无法详细解释发生了什么,但它似乎有效。请记住,Cordova 创建了该platforms/android文件夹,因此它可能会被某些操作覆盖。

回答by storm_to

The bottom bar on Android is called the Navigation Bar and the mode you are looking for is called Immersive Mode. Those terms may help you with future web searches. Try using this plugin https://github.com/mesmotronic/cordova-fullscreen-plugin

Android 上的底部栏称为导航栏,您正在寻找的模式称为沉浸模式。这些术语可能会帮助您进行未来的网络搜索。尝试使用这个插件 https://github.com/mesmotronic/cordova-fullscreen-plugin