Android_启动页

android 启动页的实现

  • 需要解决的问题

    一般app打开的时候,总是先展示一页图片.这个图片如果写在splashActivity里面,
    当需要初始化的内容过多的时候,app启动后会有短暂的黑屏或者白屏状态.
    这里我们只解决黑屏或者白屏的问题.这儿就需要用到activity的theme了.
    
  • 我们需要自定义style,在values文件夹找到styles.xml,编写以下内容:

         <style name="SplashTheme" parent="Theme.AppCompat">
            <item name="android:windowBackground">@drawable/splash_background</item>
        </style>
    
  • 编写splash_background.xml,在drawable文件夹,新建splash_background.xml文件

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- 设置背景图片 -->
        <item>
            <bitmap
                android:gravity="center"
                android:src="@drawable/zy02_splash" />
        </item>
    </layer-list>
    
  • 在activity配置中使用

     <activity
           android:name=".ui.activity.SplashActivity"
           android:theme="@style/SplashTheme"
           android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
           <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
      </activity>
    
  • 这时splashActivity就不用再布局中写background的了,可以指定为android:background=”@android:color/transparent”.

猜你喜欢

转载自blog.csdn.net/qq_25452989/article/details/78525523