我像许多其他情况一样定义了飞溅屏幕,但它对我不起作用,我不明白为什么。
图像有任何限制吗?也尝试了许多其他图像这是我的splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item>
<bitmap
android:gravity="center"
android:src="@drawable/splash_logo" />
</item>
</layer-list>
在此处,Android Studio中的Splash.xml文件的预览看起来很完美。比我创建了这样的风格
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/splash</item>
</style>
并将其分配给清单中的活动主题
<activity
android:theme="@style/AppTheme.Launcher"
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这是我的活动的
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.AppTheme)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
当活动加载时,显示空白的白屏而不是图像,也许一秒钟。我搜索了这种方法,似乎这是其他人所做的。不明白怎么了
编辑:我已经对另一个设备OS 5.0进行了测试,并且可以使用,但是6.0不
edit
将其从您的活动中删除
setTheme(R.style.AppTheme)
尝试这个
style.xml
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_background</item>
</style>
splash_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorPrimary" />
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher" />
</item>
</layer-list>
plashactivity
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
startActivity(new Intent(SplashActivity.this, MainActivity.class));
// close splash activity
finish();
}
}
清单
<activity android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这应该是评论。但是我不能发表评论。我遇到了同样的问题。请检查您的图像大小。尝试压缩图像并重试,它可能会对您有所帮助。请让我知道。