【发布时间】:2018-07-20 13:10:30
【问题描述】:
我正在尝试向我的 Android 应用添加启动画面。
我一直遵循here 的指示。这是我理解的标准方式,而且看起来合乎逻辑。
所以真的很简单吧?创建可绘制资源,在主题中使用它作为windowBackground,使用主题?好吧,这对我不起作用...
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="euroicc.sicc">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme.Splashscreen">
<activity android:name="euroicc.sicc.ui.MainActivity"
android:theme="@style/AppTheme.Splashscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
风格:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:spinnerDropDownItemStyle">@style/mySpinnerItemStyle</item>
<item name="android:itemBackground">@color/main_background</item>
<item name="android:textColor">@color/text_default</item>
<!--<item name="android:popupMenuStyle">@style/MyAlertDialog</item>-->
</style>
<style name="AppTheme.Splashscreen" parent="AppTheme">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowBackground">@drawable/splashscreen_drawable</item>
</style>
</resources>
splashscreen_drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_green_light"></solid>
</shape>
</item>
<item>
<bitmap android:src="@drawable/splashschreen_eicc"
android:gravity="center"></bitmap>
</item>
</layer-list>
我尝试了其他网站的其他代码,但似乎没有任何效果。
仅白色背景显示不到一秒钟(大约),然后应用程序开始运行。我在主要活动的 onCreate 方法中设置了主题 AppTheme,因此它始终使用它的默认主题,但开始时除外。
我还覆盖了 onPause 和 onResume,但我称它们为超级,所以这应该不是问题。
我正在 v7.0.0 上进行测试,但这也应该不是问题?
我有更多样式,但我从示例代码中删除了它们,因为它们用于 xml 文件中的对话框和元素,而不是用于活动。
那么问题是什么,我该如何解决?当我第一次阅读启动画面时,我认为设置 windowBackground 就足够了
【问题讨论】:
-
我试过你的代码,它工作正常。尝试清理 -> 构建
-
@RahulKumar 没用):
-
在 API 21 上测试了您的代码,运行良好。唯一有点不寻常的是,我只为活动设置
AppTheme.Splashscreen(为应用程序设置AppTheme)。无论如何,我想知道哪里出了问题,因为这正是我使用的方法 -
@bwt 是的,我知道,但我很绝望,所以我把它放在清单中的任何地方。无论哪种方式,我在 Main Activity 的 onCreate 上设置了不同的主题,因此应用程序使用正确的主题。
-
所以...呃...它现在正在工作。我真的什么也没做。只是周末下班。我真的很困惑为什么以前会发生这种情况,但现在没关系。
标签: android user-interface splash-screen