【问题标题】:Ionic splash screen configuration and background离子闪屏配置和背景
【发布时间】:2016-04-11 18:16:15
【问题描述】:

我在我的 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>

【问题讨论】:

  • 闪屏前是不是只有灰色闪屏?

标签: cordova ionic-framework


【解决方案1】:

我看到了您的担忧,闪屏前的灰色闪屏。 问题是启动的默认活动具有灰色背景颜色主题。 我将向您展示的解决方案 - 您将在两个文件中进行更改: project\platforms\android\app\src\May\AndroidManifest.xmlproject\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>

@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>

希望能帮到你。

【讨论】:

    【解决方案2】:

    您必须在根目录中编辑 config.xml。 如果您使用ionic buildionic run 构建应用程序,您在 patform 目录中所做的所有更改都将被覆盖。

    看看来自 ionic 的 splashscreen 描述。

    【讨论】:

      【解决方案3】:

      首先你应该创建图标和启动画面(看这里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.tsapp.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();
      
      
          });
      

      【讨论】:

        猜你喜欢
        • 2014-07-17
        • 2015-08-30
        • 1970-01-01
        • 2017-11-21
        • 2015-08-15
        • 2016-05-26
        • 1970-01-01
        • 2021-06-24
        • 1970-01-01
        相关资源
        最近更新 更多