我正在制作一个android应用程序,我希望它处于沉浸式模式,我用一个插件完成了它,但我无法在带有凹槽的android设备上(顶部和底部的黑条)进行沉浸式工作。我怎么才能使用整个屏幕?
所以我读了很多解决方案:
setTimeout(function(){
if (window.AndroidFullScreen) {
window.AndroidFullScreen.immersiveMode();
AndroidFullScreen.showUnderStatusBar();
AndroidFullScreen.showUnderSystemUI();
}, 2000);(另外,我需要使用一个超时来应用更改,我不知道为什么,无论如何,在应用程序启动时应用代码时,我使用的是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
);但是问题是,系统UI没有隐藏,当我从顶部拖动打开通知菜单并隐藏它时,UI最终会取消显示,但是屏幕返回到有黑条,所以它就像旧的immersiveMode() (同样,这段代码也在setTimeOut中)。
我的config.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>因此,当我在插件中应用immersiveMode()时,就有了这个问题:

对于其他代码,UI不会消失,当我打开通知菜单并隐藏它时,它会再次返回到第一个图像。

我想要的是这样,但没有UI显示。
谢谢。
发布于 2019-01-25 16:16:39
我让它起作用了。因此,我只需要使用以下内容添加styles.xml:
<resources>
<style name="Full">
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
</resources>因此,我创建了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>资源-文件,在文件夹值中添加styles.xml - v28在正确的路径中,v28是用于28 sdk的,所以是Android9。
然后我使用了两次edit,第一次我修改应用程序以添加android:resizeableActivity="false“,这是为了使元数据android.max_aspect工作,而android.max_aspect强制android使用屏幕的所有纵横比。
另一个编辑-配置我在活动中添加了我的自定义样式,如果我把它放在我的应用程序中,它将不能工作,所以我把它放在这里。
然后,使用插件函数immersiveMode()一切都很好。
我在这里找到了解决方案:https://proandroiddev.com/making-notch-friendly-apps-for-android-75776272be5c
https://stackoverflow.com/questions/54260941
复制相似问题