国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

如何正確實現Android啟動屏畫面的方法(避免白屏)

2019-10-22 18:14:36
字體:
來源:轉載
供稿:網友

Android啟動屏不正確的實現可能會導致用戶長時間等待,或者可能會出現黑白屏。這里簡單演示如何正確實現Android啟動屏。

演示分為以下幾個步驟:

  1. 在res/drawable文件夾中創建splash_background.xml文件。
  2. 編輯res/values/styles.xml
  3. 創建java/.../SplashActivity
  4. 編輯manifests/AndroidManifest.xml

1、在res/drawable文件夾中創建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 android:gravity="center" android:width="100dp" android:height="100dp">    <bitmap      android:gravity="fill_horizontal|fill_vertical"      android:src="@drawable/logo"/>  </item></layer-list>

2、編輯res/values/styles.xml

這里的樣式用于啟動畫面。 這是為了在啟動屏幕時隱藏操作欄。

<resources>  <!-- 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 name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">    <item name="android:windowBackground">@drawable/splash_background</item>  </style></resources>

3、創建java/.../SplashActivity

一旦App啟動,SplashActivity將啟動,然后轉移到MainActivity。

package com.example.jtdan.goodSplash;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;public class SplashActivity extends AppCompatActivity {  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    //switch from splash activity to main activity    Intent intent = new Intent(this, MainActivity.class);    startActivity(intent);    finish();  }}

4、編輯manifests/AndroidManifest.xml

在清單文件中添加新的啟動畫面Activity。

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"  package="com.example.jtdan.goodSplash">  <application    android:allowBackup="true"    android:icon="@mipmap/ic_launcher"    android:label="goodSplash"    android:roundIcon="@mipmap/ic_launcher_round"    android:supportsRtl="true"    android:theme="@style/AppTheme">    <activity android:name="com.example.jtdan.goodSplash.SplashActivity" android:theme="@style/SplashTheme">      <intent-filter>        <action android:name="android.intent.action.MAIN" />        <category android:name="android.intent.category.LAUNCHER" />      </intent-filter>    </activity>    <activity android:name="com.example.jtdan.goodSplash.MainActivity"></activity>  </application></manifest>

示例源碼地址:https://github.com/mrjoedang/goodSplash

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 神木县| 谷城县| 四子王旗| 仁化县| 陵川县| 大厂| 平顶山市| 盖州市| 广南县| 申扎县| 广德县| 龙游县| 内乡县| 花莲市| 灯塔市| 通州区| 阿坝县| 尼玛县| 密山市| 大港区| 隆德县| 珠海市| 五华县| 西宁市| 普洱| 万安县| 平昌县| 德惠市| 上思县| 常山县| 青冈县| 广宁县| 金川县| 武穴市| 巴彦县| 新巴尔虎左旗| 星座| 铜山县| 遂昌县| 靖安县| 教育|