老生常谈的问题,直接设置android:windowBackground全屏的图片,太消耗内存,这里使用layer-list设置全全屏的背景图,直接上代码
给activity设置android:theme="@style/welcome"(相较于给Application设置,给activity设置更合理,)
<!--主界面-->
<activity
android:name=".activity.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:exported="true"
android:launchMode="singleTask"
android:label="@string/app_name"
android:theme="@style/welcome"
android:screenOrientation="sensorLandscape">
</activity>
定义style
<style name="welcome" parent="AppTheme">
<item name="android:windowBackground">@drawable/welcome_layer_list</item>
</style>
定义layer-list
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/white"/>
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/welcome"/>
</item>
</layer-list>
这样就成功了
**最后别忘了设置 getWindow().setBackgroundDrawable(null); **
public abstract class AbsBaseActivity extends AppCompatActivity {
public Context context;
public Unbinder unbinder;
//是否是当前activity
public boolean isCurrentActivity;
@Override
@DebugLog
protected void onCreate(@Nullable Bundle savedInstanceState) {
getWindow().setBackgroundDrawable(null);
super.onCreate(savedInstanceState);
context = this;
isCurrentActivity = true;
setContentView();
//添加Activity到堆栈
AppManager.getAppManager().addActivity(this);
//绑定view
bindKnife();
// bindButterKnife();
viewInit();
dataInit();
eventInit();
}
}