Fra*_*lez 3 javascript android cordova
我正在制作一个 Android 应用程序,我希望它处于沉浸式模式,我使用插件完成了它,但我无法在带有缺口(顶部和底部的黑条)的 Android 设备上进行沉浸式工作。如何使用整个屏幕?
所以我读了很多解决方案:
setTimeout(function(){
if (window.AndroidFullScreen) {
window.AndroidFullScreen.immersiveMode();
AndroidFullScreen.showUnderStatusBar();
AndroidFullScreen.showUnderSystemUI();
}, 2000);
Run Code Online (Sandbox Code Playgroud)
(我还需要使用超时来应用更改,我不知道为什么,无论如何要在应用程序启动时应用代码,我正在使用 deviceready。
AndroidFullScreen.setSystemUiVisibility(
AndroidFullScreen.SYSTEM_UI_FLAG_LAYOUT_STABLE
| AndroidFullScreen.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| AndroidFullScreen.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| AndroidFullScreen.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| AndroidFullScreen.SYSTEM_UI_FLAG_FULLSCREEN
| AndroidFullScreen.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
, successFunction, errorFunction
);
Run Code Online (Sandbox Code Playgroud)
但问题是系统UI没有隐藏,当我从顶部拖动打开通知菜单并将其隐藏时,UI最终消失但屏幕又回到有黑条,所以它就像旧的沉浸模式()(同样这段代码又在setTimeOut中)。
我的配置.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.adia.security" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<platform name="android">
<allow-intent href="market:*" />
<preference name="AndroidLaunchMode" value="singleInstance" />
<preference name="DisallowOverscroll" value="true" />
<preference name="KeepRunning" value="true" />
</platform>
<edit-file parent="/manifest/application" target="AndroidManifest.xml">
<meta-data android:name="android.max_aspect" android:value="2.1" />
<activity android:resizeableActivity="false" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
</edit-file>
<preference name="Fullscreen" value="true" />
<preference name="StatusBarOverlaysWebView" value="true" />
<plugin name="cordova-plugin-fullscreen" spec="1.2.0" />
<plugin name="cordova-plugin-splashscreen" spec="5.0.2" />
<engine name="android" spec="^7.1.4" />
</widget>
Run Code Online (Sandbox Code Playgroud)
所以当我使用该插件应用immersiveMode()时,我得到了这个:

与其他代码一起,用户界面不会消失,当我打开通知菜单并将其隐藏时,它会再次返回到第一张图像。

我想要的是像这样但不显示用户界面。
谢谢。
我成功了。所以我只需要添加 styles.xml 并添加以下内容:
<resources>
<style name="Full">
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
所以我创建了 styles.xml 并将其添加到我的 www 文件夹中,然后将其添加到我的平台 android 部分中的 config.xml 中:
<platform name="android">
<resource-file src="www/styles.xml" target="app/src/main/res/values-v28/styles.xml" />
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:resizeableActivity="false"/>
</edit-config>
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/activity">
<activity android:theme="@style/Full"/>
</edit-config>
<config-file parent="./application" target="AndroidManifest.xml">
<meta-data android:name="android.max_aspect" android:value="5.0" />
</config-file>
</platform>
Run Code Online (Sandbox Code Playgroud)
资源文件,在正确路径的文件夹values-v28中添加styles.xml,v28适用于28 sdk,因此Android 9。
然后我使用 edit-config 两次,第一次修改应用程序以添加 android:resizeableActivity="false" ,以使元数据 android.max_aspect 起作用,并且 android.max_aspect 强制 android 使用所有方面 -屏幕比例。
另一个编辑配置是我在活动中添加自定义样式,如果我将其放入我的应用程序中,它将无法工作,所以我将其放在这里。
然后使用插件函数immersiveMode()一切正常。
我在这里得到了解决方案: https://proandroiddev.com/making-notch-friend-apps-for-android-75776272be5c
| 归档时间: |
|
| 查看次数: |
3302 次 |
| 最近记录: |