Android启动画面实现

Android启动画面实现,第1张

概述每个Android应用程序启动之后都会出现一个Splash启动界面,显示产品LOGO、公司LOGO或者开发者信息。如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥的时间,提高用户体验。1.splash.xml布局文件12345678910111213<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".SplashActivity" ><ImageViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/welcome_android"android:scaleType="fitCenter" /></RelativeLayout>2.SplashActivity类,使用Handler的postDelayed方法,3秒后执行跳转到主视图12345678910111213141516171819202122232425262728293031323334353637383940414243package cn.eoe.leigo.splash;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.os.Handler;/**** @{#} SplashActivity.java Create on 2013-5-2 下午9:10:01** class desc: 启动画面** <p>Copyright: Copyright(c) 2013 </p>* @Version 1.0* @Author <a href="mailto:gaolei_xj@163.com">Leo</a>***/public class SplashActivity extends Activity {//延迟3秒private static final long SPLASH_DELAY_MILLIS = 3000;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.splash);// 使用Handler的postDelayed方法,3秒后执行跳转到MainActivitynew Handler().postDelayed(new Runnable() {public void run() {goHome();}}, SPLASH_DELAY_MILLIS);}private void goHome() {Intent intent = new Intent(SplashActivity.this, MainActivity.class);SplashActivity.this.startActivity(intent);SplashActivity.this.finish();}}3.配置AndroidManifest.xml123456789101112131415161718192021222324252627282930<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"package="cn.eoe.leigo.splash"android:versionCode="1"android:versionName="1.0" ><uses-sdkandroid:minSdkVersion="10"android:targetSdkVersion="10" /><applicationandroid:icon="@drawable/logo"android:label="@string/app_name" ><activityandroid:name=".SplashActivity"android:configChanges="keyboardHidden"android:label="@string/app_name"android:launchMode="singleTask"android:screenOrientation="portrait"android:theme="@android:style/Theme.NoTitleBar.Fullscreen" ><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activity android:name=".MainActivity" /></application></manifest>

每个AndroID应用程序启动之后都会出现一个Splash启动界面,显示产品logo、公司logo或者开发者信息。如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥的时间,提高用户体验。

1.splash.xml布局文件

<span &gt;<ImageV<a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>w</span>    <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:layout_w<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>th=</span><span &gt;"match_parent"</span>    <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:layout_height=</span><span &gt;"match_parent"</span>    <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:background=</span><span &gt;"@drawable/welcome_andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>"</span>    <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:scaleType=</span><span &gt;"fitCenter"</span> <span &gt;/></span>

<span >

2.SplashActivity类,使用Handler的postDelayed方法,3秒后执行跳转到主视图

<span >import <span >androID.app.Activity<span >;
<span >import <span >androID.content.Intent<span >;
<span >import <span >androID.os.Bundle<span >;
<span >import <span >androID.os.Handler<span >;

<span >/*
<span >

<span > @{#} SplashActivity.java Create on 2013-5-2 下午9:10:01
<span >

<span > class desc: 启动画面
<span >

<span >

copyright: copyright(c) 2013


<span >
@Version 1.0

<span > @Author <a href="mailto:gaolei_xj@163.com">Leo

<span >

<span >

<span >
/

<span >public
<span >class
<span >SplashActivity <span >extends <span >Activity <span >{

<span &gt;//延迟3秒 </span><span &gt;private</span> <span &gt;static</span> <span &gt;final</span> <span &gt;long</span> <span &gt;SPLASH_DELAY_MIL<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>S</span> <span &gt;=</span> <span &gt;3000</span><span &gt;;</span><span &gt;@Overr<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>e</span><span &gt;protected</span> <span &gt;vo<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a></span> <span &gt;onCreate</span><span &gt;(</span><span &gt;Bundle</span> <span &gt;savedInstanceState</span><span &gt;)</span> <span &gt;{</span>    <span &gt;super</span><span &gt;.</span><span &gt;onCreate</span><span &gt;(</span><span &gt;savedInstanceState</span><span &gt;);</span>    <span &gt;setContentV<a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>w</span><span &gt;(</span><span &gt;R</span><span &gt;.</span><span &gt;layout</span><span &gt;.</span><span &gt;splash</span><span &gt;);</span>    <span &gt;// <a href="https://m.jb51.cc/tag/shiyong/" target="_blank" >使用</a>Handler的postDelayed<a href="https://www.jb51.cc/tag/fangfa/" target="_blank" >方法</a>,3秒<a href="https://www.jb51.cc/tag/houzhixing/" target="_blank" >后执行</a><a href="https://www.jb51.cc/tag/tiaozhuan/" target="_blank" >跳转</a>到MainActivity </span>    <span &gt;new</span> <span &gt;Handler</span><span &gt;().</span><span &gt;postDelayed</span><span &gt;(</span><span &gt;new</span> <span &gt;Runnable</span><span &gt;()</span> <span &gt;{</span>        <span &gt;pub<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>c</span> <span &gt;vo<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a></span> <span &gt;run</span><span &gt;()</span> <span &gt;{</span>            <span &gt;goHome</span><span &gt;();</span>        <span &gt;}</span>    <span &gt;},</span> <span &gt;SPLASH_DELAY_MIL<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>S</span><span &gt;);</span><span &gt;}</span><span &gt;private</span> <span &gt;vo<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a></span> <span &gt;goHome</span><span &gt;()</span> <span &gt;{</span>    <span &gt;Intent</span> <span &gt;intent</span> <span &gt;=</span> <span &gt;new</span> <span &gt;Intent</span><span &gt;(</span><span &gt;SplashActivity</span><span &gt;.</span><span &gt;this</span><span &gt;,</span> <span &gt;MainActivity</span><span &gt;.</span><span &gt;class</span><span &gt;);</span>    <span &gt;SplashActivity</span><span &gt;.</span><span &gt;this</span><span &gt;.</span><span &gt;startActivity</span><span &gt;(</span><span &gt;intent</span><span &gt;);</span>    <span &gt;SplashActivity</span><span &gt;.</span><span &gt;this</span><span &gt;.</span><span &gt;finish</span><span &gt;();</span><span &gt;}</span>

<span >}

3.配置AndroIDManifest.xml

<span &gt;<</span><span &gt;uses</span><span &gt;-</span><span &gt;sdk</span>    <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;minSdkVersion</span><span &gt;=</span><span &gt;"10"</span>    <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;targetSdkVersion</span><span &gt;=</span><span &gt;"10"</span> <span &gt;/></span><span &gt;<</span><span &gt;app<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>cation</span>    <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;icon</span><span &gt;=</span><span &gt;"@drawable/<a href="https://www.jb51.cc/tag/logo/" target="_blank" >logo</a>"</span>    <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;label</span><span &gt;=</span><span &gt;"@string/app_<a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a>"</span> <span &gt;></span>    <span &gt;<</span><span &gt;activity</span>        <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;<a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a></span><span &gt;=</span><span &gt;".SplashActivity"</span>        <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;con<a href="https://www.jb51.cc/tag/fig/" target="_blank" >fig</a>Changes</span><span &gt;=</span><span &gt;"keyboardH<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>den"</span>        <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;label</span><span &gt;=</span><span &gt;"@string/app_<a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a>"</span>        <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;launchMode</span><span &gt;=</span><span &gt;"singleTask"</span>        <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;scree<a href="https://www.jb51.cc/tag/nor/" target="_blank" >nor</a><a href="https://m.jb51.cc/tag/IE/" target="_blank" >IE</a>ntation</span><span &gt;=</span><span &gt;"portrait"</span>        <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;<a href="https://m.jb51.cc/tag/theme/" target="_blank" >theme</a></span><span &gt;=</span><span &gt;"@andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:style/<a href="https://m.jb51.cc/tag/theme/" target="_blank" >theme</a>.No<a href="https://m.jb51.cc/tag/Title/" target="_blank" >Title</a><a href="https://m.jb51.cc/tag/bar/" target="_blank" >bar</a>.F<a href="https://m.jb51.cc/tag/ul/" target="_blank" >ul</a>lscreen"</span> <span &gt;></span>        <span &gt;<</span><span &gt;intent</span><span &gt;-</span><span &gt;filter</span><span &gt;></span>            <span &gt;<</span><span &gt;action</span> <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;<a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a></span><span &gt;=</span><span &gt;"andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>.intent.action.MAIN"</span> <span &gt;/></span>            <span &gt;<</span><span &gt;<a href="https://m.jb51.cc/tag/category/" target="_blank" >category</a></span> <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;<a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a></span><span &gt;=</span><span &gt;"andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>.intent.<a href="https://m.jb51.cc/tag/category/" target="_blank" >category</a>.LAUNCHER"</span> <span &gt;/></span>        <span &gt;</</span><span &gt;intent</span><span &gt;-</span><span &gt;filter</span><span &gt;></span>    <span &gt;</</span><span &gt;activity</span><span &gt;></span>    <span &gt;<</span><span &gt;activity</span> <span &gt;andro<a href="https://m.jb51.cc/tag/ID/" target="_blank" >ID</a>:</span><span &gt;<a href="https://m.jb51.cc/tag/name/" target="_blank" >name</a></span><span &gt;=</span><span &gt;".MainActivity"</span> <span &gt;/></span><span &gt;</</span><span &gt;app<a href="https://m.jb51.cc/tag/li/" target="_blank" >li</a>cation</span><span &gt;></span>

<span ></<span >manifest<span >>

以上是内存溢出为你收集整理的Android启动画面实现全部内容,希望文章能够帮你解决Android启动画面实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1149751.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)