android系統開機畫面
Android Splash Screen is the first screen visible to the user when the application’s launched. Splash screen is one of the most vital screens in the application since it’s the user’s first experience with the application.
Android啟動畫面是啟動應用程序時用戶可見的第一個屏幕。 閃屏是應用程序中最重要的屏幕之一,因為它是用戶對應用程序的首次體驗。
Splash screens are used to display some animations (typically of the application logo) and illustrations while some data for the next screens are fetched.
啟動屏幕用于顯示某些動畫(通常是應用程序徽標)和插圖,同時獲取下一個屏幕的一些數據。
Typically, the Activity that has the following intent filter set in the AndroidManifest.xml
file is the Splash Activity.
通常,在AndroidManifest.xml
文件中設置了以下意圖過濾器的Activity是Splash Activity。
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
There are few ways to create the initial screen i.e. Splash Screen of the application. Let’s see each of them.
有幾種創建初始屏幕的方法,即應用程序的啟動屏幕。 讓我們看看它們中的每一個。
SplashActivity.java
package com.journaldev.splashscreen;import android.content.Intent;import android.os.Handler;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); new Handler().postDelayed(new Runnable() { @Override public void run() { // This method will be executed once the timer is over Intent i = new Intent(SplashActivity.this, MainActivity.class); startActivity(i); finish(); } }, 5000); }}
This is how we normally create the layout of our Splash Screen in our application: activity_splash.xml
通常,這就是我們在應用程序中創建啟動畫面布局的方式: activity_splash.xml
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:andro xmlns:app="https://schemas.android.com/apk/res-auto" xmlns:tools="https://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black" tools:context="com.journaldev.splashscreen.SplashActivity"> <ImageView android: android:layout_width="72dp" android:layout_height="72dp" android:src="@mipmap/ic_launcher" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminate="true" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@id/imageView" /></android.support.constraint.ConstraintLayout>
Let’s keep the MainActivity.java
empty for now.
讓我們MainActivity.java
保持MainActivity.java
空。
The output produced from the above implementation of SplashScreen is given below. We’ve set the theme of the SplashActivity to Theme.AppCompat.NoActionBar in the AndroidManifest.xml
file.
下面是上述SplashScreen的實現所產生的輸出。 我們設置了SplashActivity到Theme.AppCompat.NoActionBar在主題AndroidManifest.xml
文件。
Did you see the blank page that came up before the Splash Screen was visible to you?
在啟動畫面可見之前,您是否看到空白頁面?
The above approach isn’t the correct approach. It’ll give rise to cold starts.
上面的方法不是正確的方法。 它會引起冷啟動 。
The purpose of a Splash Screen is to quickly display a beautiful screen while the application fetches the relevant content if any (from network calls/database). With the above approach, there’s an additional overhead that the SplashActivity
uses to create its layout.
啟動屏幕的目的是在應用程序獲取相關內容(從網絡調用/數據庫)中獲取相關內容時,快速顯示漂亮的屏幕。 使用上述方法, SplashActivity
使用額外的開銷來創建其布局。
It’ll give rise to slow starts to the application which is bad for the user experience (wherein a blank black/white screen appears).
它將導致應用程序啟動緩慢,這不利于用戶體驗(其中出現黑屏/白屏)。
The cold start appears since the application takes time to load the layout file of the Splash Activity. So instead of creating the layout, we’ll use the power of the application theme to create our initial layout.
由于應用程序需要時間來加載Splash Activity的布局文件,因此出現冷啟動。 因此,我們將使用應用程序主題的功能來創建初始布局,而不是創建布局。
Application theme is instantiated before the layout is created. We’ll set a drawable inside the android:windowBackground
attribute that’ll comprise of the Activity’s background and an icon using layer-list as shown below.
在創建布局之前,將實例化應用程序主題。 我們將在android:windowBackground
屬性內設置一個drawable,該屬性android:windowBackground
Activity的背景和使用layer-list的圖標組成,如下所示。
splash_background.xml
splash_background.xml
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:andro> <item android:drawable="@android:color/black" /> <item> <bitmap android:gravity="center" android:src="@mipmap/ic_launcher" /> </item></layer-list>
We’ll set the following style as the theme of the activity.
我們將以下樣式設置為活動的主題。
styles.xml
styles.xml
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar"> <item name="android:windowBackground">@drawable/splash_background</item> </style>
The SplashActivity.java file should look like this:
SplashActivity.java文件應如下所示:
package com.journaldev.splashscreen;import android.content.Intent;import android.os.Handler;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); new Handler().postDelayed(new Runnable() { @Override public void run() { // This method will be executed once the timer is over Intent i = new Intent(SplashActivity.this, MainActivity.class); startActivity(i); finish(); } }, 5000); }}
Note: the theme of the activity is set before anything else. Hence the above approach would give our app a quicker start.
注意:活動的主題設置在其他任何主題之前。 因此,以上方法將使我們的應用程序更快速地啟動。
Using the theme and removing the layout from the SplashActivity is the correct way to create a splash screen. This brings an end to android splash screen tutorial. You can download the final Android Splash Screen Project from the link below.
使用主題并從SplashActivity中刪除布局是創建初始屏幕的正確方法。 這結束了android啟動畫面教程。 您可以從下面的鏈接下載最終的Android Splash Screen Project。
Download Android Splash Screen Example Project 下載Android啟動畫面示例項目
翻譯自: https://www.journaldev.com/17831/android-splash-screen
android系統開機畫面
146555.html
本文由 貴州做網站公司 整理發布,部分圖文來源于互聯網,如有侵權,請聯系我們刪除,謝謝!
網絡推廣與網站優化公司(網絡優化與推廣專家)作為數字營銷領域的核心服務提供方,其價值在于通過技術手段與策略規劃幫助企業提升線上曝光度、用戶轉化率及品牌影響力。這...
在當今數字化時代,公司網站已成為企業展示形象、傳遞信息和開展業務的重要平臺。然而,對于許多公司來說,網站建設的價格是一個關鍵考量因素。本文將圍繞“公司網站建設價...
在當今的數字化時代,企業網站已成為企業展示形象、吸引客戶和開展業務的重要平臺。然而,對于許多中小企業來說,高昂的網站建設費用可能會成為其發展的瓶頸。幸運的是,隨...
閱文動漫屬于哪個公司?屬于騰訊國內已申請授權同名電影影視、類游戲、動漫、舞臺劇、音頻資源等產品邏輯的侵刪文學著作大部分都圖源阿里文學,不僅如此《盜墓筆記》《鬼吹燈》《斗破蒼穹》《瑯琊榜》《擇天記》《全職高手》《將夜》《扶搖皇后》《凰權》《慶余年》等數十部超人氣優秀作品,阿里文學如今對國內創意產業發展極富市場影響力的主要影視ip源頭解決。騰訊動漫買下哪些動漫的版權?你好,網易買下了很多日漫原創者,可...
阿里巴巴有銀行嗎?沒錯,阿里巴巴作為大股東,是五大民營銀行之一。阿里巴巴網絡科技有限公司(簡稱阿里巴巴集團)由前英語教師馬云為首的18人于1999年在杭州創立。他們認為,互聯網可以創造一個公平的競爭環境,讓小企業通過創新和技術擴大業務,在國內或全球市場競爭時處于更有利的地位。阿里巴巴集團運營多項業務,此外,還從關聯公司的業務和服務中獲得運營商業生態系統的支持。相關公司的業務包括:淘寶、天貓、聚劃算...
黃廟廣場西北,各超市樓下,肯德基旁邊,12號線大門旁邊!沈陽,斯卡拉地址?沈陽有兩個斯卡拉。一個是南風Scala 一個是西部葡萄酒城斯卡拉 南風在北陵公園。西方葡萄酒城位于戴維營。;標準普爾。;司機知道打車的一切。沈陽那個迪吧最好?東方斯卡拉是沈陽知名的老牌演繹酒吧,位于沈陽市中心,建筑面積4000平方米,總投資2000萬元。設計充分體現時尚元素,頂級的專業設備,世界級的3S服務品質,時尚的娛樂...