android系统开机画面_Android开机画面

android系统开机画面_Android开机画面制作android开机画面AndroidSplashScreenisthefirstscreenvisibletotheuserwhentheapplication’slaunched.Splashscreenisoneofthemostvitalscreensintheapplicationsinceit’stheuser’sfirs…

大家好,又见面了,我是你们的朋友全栈君。

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.

启动屏幕用于显示某些动画(通常是应用程序徽标)和插图,同时获取下一个屏幕的一些数据。

Android开机画面 (Android Splash Screen)

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>

Android启动画面示例项目结构 (Android Splash Screen Example Project Structure)

There are few ways to create the initial screen i.e. Splash Screen of the application. Let’s see each of them.

有几种创建初始屏幕的方法,即应用程序的启动屏幕。 让我们看看它们中的每一个。

闪屏经典方法 (Splash Screen Classical Approach)

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:android="https://schemas.android.com/apk/res/android"
    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:id="@+id/imageView"
        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).

它将导致应用程序启动缓慢,这不利于用户体验(其中出现黑屏/白屏)。

带有正确方法的Android启动画面示例 (Android Splash Screen Example with Correct Approach)

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:android="https://schemas.android.com/apk/res/android">

    <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。

翻译自: https://www.journaldev.com/17831/android-splash-screen

android系统开机画面

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/146555.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 个人微信api接口调用代码[通俗易懂]

    个人微信api接口调用代码[通俗易懂]个人微信api接口1、微信好友收发消息/***给微信好友发消息*@authorwechatno:tangjinjinwx*@bloghttp://www.wlkankan.cn*/@AsyncpublicvoidhandleMsg(ChannelHandlerContextctx,TransportMessagevo,StringcontentJsonStr){try{…

    2022年10月2日
    3
  • 计算机竞赛初赛,计算机基本应用能力竞赛试题(初赛)(1)_已测

    计算机竞赛初赛,计算机基本应用能力竞赛试题(初赛)(1)_已测

    2021年8月16日
    139
  • VMWare安装Win10虚拟机详细教程

    VMWare安装Win10虚拟机详细教程1. 安装Win10之前,先检查VMware虚拟网卡是否正常打开控制面板,找到网络和Internet点击更改设备器配置,查看VMware虚拟网卡是否存在和已启用2. 还原默认设置(网卡正常跳过此步骤)点击VMware中的—编辑—虚拟网络编辑器点击左下角的—还原默认设置3. 虚拟网卡正常后,开始创建虚拟机4. 选择—自定义(高级)©5. 根据自己安装的VMware选择合适的—硬件兼容性6. 选择自己所需要的Windows系统镜像进行安装7.

    2022年6月26日
    125
  • 深入理解拉格朗日乘子法(Lagrange Multiplier) 和KKT条件「建议收藏」

    深入理解拉格朗日乘子法(Lagrange Multiplier) 和KKT条件「建议收藏」在求解最优化问题中,拉格朗日乘子法(LagrangeMultiplier)和KKT(KarushKuhnTucker)条件是两种最常用的方法。在有等式约束时使用拉格朗日乘子法,在有不等约束时使用KKT条件。  我们这里提到的最优化问题通常是指对于给定的某一函数,求其在指定作用域上的全局最小值(因为最小值与最大值可以很容易转化,即最大值问题可以转化成最小值问题)。提到KKT条件一般会附带的…

    2022年10月8日
    4
  • 一遍过的刷四史脚本教程「建议收藏」

    一遍过的刷四史脚本教程「建议收藏」首先你得有台电脑和一部手机手机进行抓包提前打开四史的界面,切换至后台,然后打开手机中的抓包软件开始抓包!进入带四史答题界面后,切换后台,打开抓包软件,一个一个打开去找抓包内容请求中Bearer后面的字符串电脑运行文件四史脚本加抓包软件传送门->>>…

    2022年6月26日
    27
  • 网络流媒体协议之——RTSP协议

    网络流媒体协议之——RTSP协议RTSP(Real-TimeStreamProtocol)协议是一个基于文本的多媒体播放控制协议,属于应用层。RTSP以客户端方式工作,对流媒体提供播放、暂停、后退、前进等操作。该标准由IETF指定,对应的协议是RFC2326。RTSP作为一个应用层协议,提供了一个可供扩展的框架,使得流媒体的受控和点播变得可能,它主要用来控制具有实时特性的数据的发送,但其本身并不用于传送流媒体数据,而

    2022年7月16日
    19

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号