Android启动画面实现

发布时间:2019-10-14 发布网站:大佬教程
大佬教程收集整理的这篇文章主要介绍了Android启动画面实现大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

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

1.splash.xml布局文件

1 2 3 4 5 6 7 8 9 10 11 12 13
<span class="nt"&gt;<ImageView</span>
    <span class="na"&gt;android:layout_width=</span><span class="s"&gt;"match_parent"</span>
    <span class="na"&gt;android:layout_height=</span><span class="s"&gt;"match_parent"</span>
    <span class="na"&gt;android:background=</span><span class="s"&gt;"@drawable/welcome_android"</span>
    <span class="na"&gt;android:scaleType=</span><span class="s"&gt;"fitCenter"</span> <span class="nt"&gt;/></span>

<span class="nt">

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

<span class="kn">import <span class="nn">android.app.Activity<span class="o">;
<span class="kn">import <span class="nn">android.content.Intent<span class="o">;
<span class="kn">import <span class="nn">android.os.Bundle<span class="o">;
<span class="kn">import <span class="nn">android.os.Handler<span class="o">;

<span class="cm">/*
<span class="cm">

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

<span class="cm"> class desc: 启动画面
<span class="cm">

<span class="cm">

Copyright: Copyright(c) 2013


<span class="cm">
@Version 1.0

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

<span class="cm">

<span class="cm">

<span class="cm">
/

<span class="kd">public
<span class="kd">class
<span class="nc">SplashActivity
<span class="kd">extends <span class="n">Activity <span class="o">{

<span class="c1"&gt;//延迟3秒 </span>
<span class="kd"&gt;private</span> <span class="kd"&gt;static</span> <span class="kd"&gt;final</span> <span class="kt"&gt;long</span> <span class="n"&gt;SPLASH_DELAY_MILLIS</span> <span class="o"&gt;=</span> <span class="mi"&gt;3000</span><span class="o"&gt;;</span>

<span class="nd"&gt;@Override</span>
<span class="kd"&gt;protected</span> <span class="kt"&gt;void</span> <span class="nf"&gt;onCreate</span><span class="o"&gt;(</span><span class="n"&gt;Bundle</span> <span class="n"&gt;savedInstanceState</span><span class="o"&gt;)</span> <span class="o"&gt;{</span>
    <span class="kd"&gt;super</span><span class="o"&gt;.</span><span class="na"&gt;onCreate</span><span class="o"&gt;(</span><span class="n"&gt;savedInstanceState</span><span class="o"&gt;);</span>
    <span class="n"&gt;setContentView</span><span class="o"&gt;(</span><span class="n"&gt;R</span><span class="o"&gt;.</span><span class="na"&gt;layout</span><span class="o"&gt;.</span><span class="na"&gt;splash</span><span class="o"&gt;);</span>

    <span class="c1"&gt;// 使用Handler的postDelayed方法,3秒后执行跳转到MainActivity </span>
    <span class="k"&gt;new</span> <span class="nf"&gt;Handler</span><span class="o"&gt;().</span><span class="na"&gt;postDelayed</span><span class="o"&gt;(</span><span class="k"&gt;new</span> <span class="n"&gt;Runnable</span><span class="o"&gt;()</span> <span class="o"&gt;{</span>
        <span class="kd"&gt;public</span> <span class="kt"&gt;void</span> <span class="nf"&gt;run</span><span class="o"&gt;()</span> <span class="o"&gt;{</span>
            <span class="n"&gt;goHome</span><span class="o"&gt;();</span>
        <span class="o"&gt;}</span>
    <span class="o"&gt;},</span> <span class="n"&gt;SPLASH_DELAY_MILLIS</span><span class="o"&gt;);</span>
<span class="o"&gt;}</span>

<span class="kd"&gt;private</span> <span class="kt"&gt;void</span> <span class="nf"&gt;goHome</span><span class="o"&gt;()</span> <span class="o"&gt;{</span>
    <span class="n"&gt;Intent</span> <span class="n"&gt;intent</span> <span class="o"&gt;=</span> <span class="k"&gt;new</span> <span class="n"&gt;Intent</span><span class="o"&gt;(</span><span class="n"&gt;SplashActivity</span><span class="o"&gt;.</span><span class="na"&gt;this</span><span class="o"&gt;,</span> <span class="n"&gt;MainActivity</span><span class="o"&gt;.</span><span class="na"&gt;class</span><span class="o"&gt;);</span>
    <span class="n"&gt;SplashActivity</span><span class="o"&gt;.</span><span class="na"&gt;this</span><span class="o"&gt;.</span><span class="na"&gt;startActivity</span><span class="o"&gt;(</span><span class="n"&gt;intent</span><span class="o"&gt;);</span>
    <span class="n"&gt;SplashActivity</span><span class="o"&gt;.</span><span class="na"&gt;this</span><span class="o"&gt;.</span><span class="na"&gt;finish</span><span class="o"&gt;();</span>
<span class="o"&gt;}</span>

<span class="o">}

3.配置AndroidManifest.xml

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<span class="o"&gt;<</span><span class="n"&gt;uses</span><span class="o"&gt;-</span><span class="n"&gt;sdk</span>
    <span class="nl"&gt;android:</span><span class="n"&gt;minSdkVersion</span><span class="o"&gt;=</span><span class="s"&gt;"10"</span>
    <span class="nl"&gt;android:</span><span class="n"&gt;targetSdkVersion</span><span class="o"&gt;=</span><span class="s"&gt;"10"</span> <span class="o"&gt;/></span>

<span class="o"&gt;<</span><span class="n"&gt;application</span>
    <span class="nl"&gt;android:</span><span class="n"&gt;icon</span><span class="o"&gt;=</span><span class="s"&gt;"@drawable/logo"</span>
    <span class="nl"&gt;android:</span><span class="n"&gt;label</span><span class="o"&gt;=</span><span class="s"&gt;"@string/app_name"</span> <span class="o"&gt;></span>
    <span class="o"&gt;<</span><span class="n"&gt;activity</span>
        <span class="nl"&gt;android:</span><span class="n"&gt;name</span><span class="o"&gt;=</span><span class="s"&gt;".SplashActivity"</span>
        <span class="nl"&gt;android:</span><span class="n"&gt;configChanges</span><span class="o"&gt;=</span><span class="s"&gt;"keyboardHidden"</span>
        <span class="nl"&gt;android:</span><span class="n"&gt;label</span><span class="o"&gt;=</span><span class="s"&gt;"@string/app_name"</span>
        <span class="nl"&gt;android:</span><span class="n"&gt;launchMode</span><span class="o"&gt;=</span><span class="s"&gt;"singleTask"</span>
        <span class="nl"&gt;android:</span><span class="n"&gt;screenOrientation</span><span class="o"&gt;=</span><span class="s"&gt;"portrait"</span>
        <span class="nl"&gt;android:</span><span class="n"&gt;theme</span><span class="o"&gt;=</span><span class="s"&gt;"@android:style/Theme.NoTitleBar.Fullscreen"</span> <span class="o"&gt;></span>
        <span class="o"&gt;<</span><span class="n"&gt;intent</span><span class="o"&gt;-</span><span class="n"&gt;filter</span><span class="o"&gt;></span>
            <span class="o"&gt;<</span><span class="n"&gt;action</span> <span class="nl"&gt;android:</span><span class="n"&gt;name</span><span class="o"&gt;=</span><span class="s"&gt;"android.intent.action.MAIN"</span> <span class="o"&gt;/></span>

            <span class="o"&gt;<</span><span class="n"&gt;category</span> <span class="nl"&gt;android:</span><span class="n"&gt;name</span><span class="o"&gt;=</span><span class="s"&gt;"android.intent.category.LAUNCHER"</span> <span class="o"&gt;/></span>
        <span class="o"&gt;</</span><span class="n"&gt;intent</span><span class="o"&gt;-</span><span class="n"&gt;filter</span><span class="o"&gt;></span>
    <span class="o"&gt;</</span><span class="n"&gt;activity</span><span class="o"&gt;></span>
    <span class="o"&gt;<</span><span class="n"&gt;activity</span> <span class="nl"&gt;android:</span><span class="n"&gt;name</span><span class="o"&gt;=</span><span class="s"&gt;".MainActivity"</span> <span class="o"&gt;/></span>
<span class="o"&gt;</</span><span class="n"&gt;application</span><span class="o"&gt;></span>

<span class="o"></<span class="n">manifest<span class="o">>

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ群:277859234,请注明来意。