41. windowBackground的使用方法

windowBackground

使用Activity的windowBackground主题属性来为启动的Activity提供一个简单的drawable,
这样在启动的时候,会先展示一个界面,
这个界面就是Manifest中设置的Style,等Activity加载完毕后,
再去加载Activity的界面,而在Activity的界面中,我们将主题重新设置为正常的主题,
从而产生一种快的感觉。

来说一下这个东西的使用,首先要在你要在第一个Activity,就是你进入app的第一个actavity的AndroidManifest里设置:

<activity android:name=".Home1Activity"
    android:theme="@style/AppThemeDrawable">

这个AppThemeDrawable是在style里自己定义的一个style风格,里面给它设置了一张图片。

<resources>
 <!-- 系统默认的style 风格 -->
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

 <!-- 自己写的的style 风格,加了个图片 -->
    <style name="AppThemeDrawable" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowBackground">@mipmap/img_bb</item>
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

然后在这个Activity里,加载布局的那个方法里,在R.layout.home1layout上面,加一句:

setTheme(R.style.AppTheme);

意思是重新设置为正常的style。AppTheme是系统默认的style。

 

猜你喜欢

转载自blog.csdn.net/weixin_42061754/article/details/81905028