我公司有一个 Android Kotlin 应用程序。
我们想在启动时显示启动画面。
在阅读了一堆 turtorial 之后,我找到了一种方法。
但是当我尝试显示
ImageView
启动画面时,它变成了白色背景。
这是我的代码:
<application
...
android:theme="@style/Theme.SplashScreen">
...
</application
<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>
<?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
或片段中的任何背景颜色上显示图像。
可能是什么问题?
任何建议如何解决这个问题?
我的 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"/>