首先,在values/styles文件下加入下面代码
<style name="AppTheme.StartingWindowTheme" >
//这里设置的是启动图片
<item name="android:windowBackground">@drawable/icon_start</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
然后,再去Androidmanifest里,在对应的Activity下添加主题样式
android:theme="@style/AppTheme.StartingWindowTheme"
在这里,我附上案例,以便参考.
Androidmanifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:name=".data.others.App"
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".ui.activity.StartActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait" //这一行是锁定屏幕代码,禁止横竖屏切换
android:theme="@style/AppTheme.StartingWindowTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
values/styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@android:color/transparent</item>
</style>
<style name="AppTheme.StartingWindowTheme" parent="AppTheme">
//这里设置的是启动图片
<item name="android:windowBackground">@drawable/icon_start</item>
</style>
</resources>
在这里,有人会问了,你在values/styles.xml里写了两个样式是怎么回事,写成一个不行吗?
不行的,首先咱们先看第二个style (AppTheme.StartingWindowTheme) 这个是设置的启动页是的背景 ,所以只设置在启动页的Activty为样式.
启动页
大家经过图片的对比会发现,看似一样作用却是不一样的.
如果只设置一个启动页样式并也把他设置在application里,其他界面背景会变成启动页图片.
如还有疑问,欢迎留言.