实现Android启动屏画面的案例-创新互联

这篇文章给大家分享的是有关实现Android启动屏画面的案例的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

创新互联建站服务紧随时代发展步伐,进行技术革新和技术进步,经过十多年的发展和积累,已经汇集了一批资深网站策划师、设计师、专业的网站实施团队以及高素质售后服务人员,并且完全形成了一套成熟的业务流程,能够完全依照客户要求对网站进行成都网站制作、成都做网站、外贸营销网站建设、建设、维护、更新和改版,实现客户网站对外宣传展示的首要目的,并为客户企业品牌互联网化提供全面的解决方案。

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>

感谢各位的阅读!关于“实现Android启动屏画面的案例”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

文章标题:实现Android启动屏画面的案例-创新互联
标题来源:https://www.cdcxhl.com/article6/djppog.html

成都网站建设公司_创新互联,为您提供网页设计公司企业网站制作ChatGPT网站策划Google品牌网站设计

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

搜索引擎优化