Android - 如何在 SplashScreen 中使用 ImageView

问题描述 投票:0回答:1

我公司有一个 Android Kotlin 应用程序。
我们想在启动时显示启动画面。
在阅读了一堆 turtorial 之后,我找到了一种方法。
但是当我尝试显示

ImageView
启动画面时,它变成了白色背景。

这是我的代码:

AndroidManifest.xml

<application
    ...
    android:theme="@style/Theme.SplashScreen">
    ...
</application

Res/values/themes/themes.xml 中的 Theme.SplashScreen

<resources xmlns:tools="http://schemas.android.com/tools">
    ...
    <style name="Theme.SplashScreen" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_background</item>
    </style>
    ...
</resources>

res/drawable/splash_background.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item android:drawable="@color/blue" />
    <item>

        <!-- This works
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher" />
        -->
        <!-- This doesn't work --> 
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:src="@drawable/ic_somePicture"
            app:tint="@color/white" />
    </item>
</layer-list>

注意我这里有两个案例:

bitmap
ImageView
案例。

  • 如果我取消注释,
    bitmap
    案例将起作用。
    在启动过程中,此图像显示在启动画面中。
  • ImageView
    案例不起作用。
    这个结果是一个完全白色的启动画面。

ImageView
“应该”有效,因为我在某些片段中使用了相同的设置。

@drawable/ic_somePicture
是我在 AndroidStudio 项目中添加的 SVG 图像。
我不能在这里展示它,因为它是我公司的财产。
请注意,我必须指定
app:tint
属性以在
splash_background.xml
或片段中的任何背景颜色上显示图像。

可能是什么问题?
任何建议如何解决这个问题?

android imageview splash-screen
1个回答
0
投票

我的 SplashScreen 中有这个设置

class MainActivity : AppCompatActivity(){
    private val SPLASH_DISPLAY_LENGTH = 5000
    override fun onCreate(s: Bundle?) {
        super.onCreate(s)
        setContentView(R.layout.welcome)
    }

    override fun onResume() {
        super.onResume()
        Handler().postDelayed({ /* Create an Intent that will start the Menu-Activity. */
            val mainIntent = Intent()
            mainIntent.setClass(applicationContext, MapsActivity::class.java)
            startActivity(mainIntent)
            finish()
        }, SPLASH_DISPLAY_LENGTH.toLong())
    }
}

图像视图

<ImageView
        android:layout_marginTop="80dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:background="@drawable/logo"
        android:id="@+id/image_splash"/>
© www.soinside.com 2019 - 2024. All rights reserved.