我已经为我的Ionic Android项目添加了一个启动画面,它运行正常 唯一的问题是,应用程序首先触发灰色屏幕(应用程序背景为白色),然后显示启动画面,然后淡出到应用程序启动时显示的灰色,然后才加载第一个应用程序视图。
我在网上搜索了可能的解决方案,但没有找到解决我问题的方法 请注意:我只在Android上测试我的应用程序,它目前只适用于Android。
我尝试弄乱config.xml
文件,但每当我构建应用程序时,配置文件都会回到默认状态。
以下是config.xml
启动画面部分:
<feature name="SplashScreen">
<param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
<param name="onload" value="true" />
</feature>
答案 0 :(得分:1)
您必须编辑根目录中的 config.xml 。
如果您使用ionic build
或ionic run
构建应用,则会覆盖您在patform目录中所做的所有更改。
查看来自离子的splashscreen描述。
答案 1 :(得分:0)
首先,您应该创建图标和启动(请查看此处http://ionicframework.com/docs/cli/icon-splashscreen.html)
然后安装ionic plugin add cordova-plugin-splashscreen
然后将以下代码添加到config.xml
<preference name="ShowSplashScreen" value="true"/>
<preference name="SplashScreen" value="screen"/>
<preference name="SplashScreenDelay" value="3000"/>
<preference name="AutoHideSplashScreen" value="false"/>
<preference name="SplashShowOnlyFirstTime" value="false"/>
<preference name="FadeSplashScreen" value="false"/>
<feature name="SplashScreen">
<param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen"/>
</feature>
加入app.ts
或app.component.ts
添加
import {Splashscreen} from 'ionic-native';
........
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
Splashscreen.hide();
});
答案 2 :(得分:0)
我看到您的担心,闪屏前的屏幕是灰色的闪光灯。
问题在于启动的默认活动具有灰色背景颜色主题。
我将向您展示的解决方案-您将在两个文件中进行更改:
project\platforms\android\app\src\May\AndroidManifest.xml
和
project\platforms\android\app\src\main\res\values\themes.xml
根据项目类型,尤其是您正在处理的版本,路径可能会有所不同。
默认情况下无法创建themes.xml
文件,在这种情况下,您必须创建它。
首先,您必须打开AndroidManifest.xml文件,并在Application标记中看到第一个活动,如下所示:
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
在默认为{p>的@android: theme
属性中
@android:style / Theme.DeviceDefault.NoActionBar
,这就是我们将要更改的内容,并放入我们的自定义主题。因此,您可以减少此值,因为我们会将其用作自定义主题的父主题。
现在转到themes.xml
文件并将其放入。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Blanc" parent="@android:style/Theme.DeviceDefault.NoActionBar">
<item name="android:windowBackground">@android:color/white</item>
</style>
</resources>
背景颜色值取决于您想要在item标签中使用的颜色,如果您要使用其他Android颜色go visit here,则在这里选择白色。您不能使用类似#fff
的值。
您猜对了,现在您必须回到我们的AndroidManifest.xml
并将@android:theme
的值设置为:@style/Theme.Blanc
是我们自定义样式的名称。
最后,AndroidManifest
如下所示:
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@style/Theme.Blanc" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
希望对您有所帮助。