自定义android启动画面

时间:2016-07-18 16:51:37

标签: android splash-screen android-theme

我使用活动主题为应用创建了启动画面。这是在Google开发人员推荐的加载时间中显示它的有效方法(https://plus.google.com/+IanLake/posts/SW7F2CJvAmU)。

我在drawable中创建了splash.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/ColorPrimary" />
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/splash" />
    </item>
</layer-list>

用它创建主题

<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splash</item>
</style>

并将此主题应用于清单

中的活动
    <activity
        android:name=".SplashActivity"
        android:launchMode="singleTop"
        android:theme="@style/SplashTheme">

现在我需要从代码中自定义启动画面。我需要更改位图和颜色,或者添加另一个项目到图层列表。怎么做?

2 个答案:

答案 0 :(得分:1)

  

我需要以编程方式在layer-list(color,bitmap)中更改它的参数

您无法通过代码执行此操作,因为您的代码尚未加载。

答案 1 :(得分:0)

为什么你不使用包含图像的布局(splash.xml)并将该布局用作逻辑方面的contentView,然后可以对图像使用一些动画,或者更改背景...... ....