您的位置:首页 > 移动开发 > Android开发

Android引导页的四种实现方式

2017-12-20 11:10 176 查看
四种方式制作引导页

1、一个splash界面

一个非常简洁的页面,停留若干秒的时间,然后进入到主界面,程序执行步骤:

在刚刚打开的时候,程序会在sharedpreference本地注册表文件中去读取是否第一次打开应用,如果是,把这个界面展示给用户看,以后第二次,第三次都不会再显示这个界面

代码展示:

创建一个SplashActivity和对应的activity_splash布局文件,在manifest文件中将SplashActivity设置为启动页

activity_splash布局文件如下:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="@mipmap/splash1">

</RelativeLayout>

SplashActivity代码如下:

package com.gn.violetapplication;

import android.app.Activity;

import android.content.Context;

import android.content.Intent;

import android.content.SharedPreferences;

import android.os.Handler;

import android.os.Bundle;

public class SplashActivity extends Activity {

    private static final long DELAY_TIME = 3000L;

    SharedPreferences preferences;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_splash);

        preferences=getSharedPreferences("user", Context.MODE_PRIVATE);

        boolean isSplashShown = preferences.getBoolean("isSplashShown",false);

        if(isSplashShown){

            startActivity(new Intent(SplashActivity.this,MainActivity.class));

            finish();

        }

        new Handler().postDelayed(new Runnable() {

            @Override

            public void run() {

                startActivity(new Intent(SplashActivity.this,MainActivity.class));

                SharedPreferences.Editor editor=preferences.edit();

                editor.putBoolean("isSplashShown", true);

                editor.commit();

                finish();

            }

        },DELAY_TIME);

    }

}

manifest文件配置如下:

<activity android:name=".SplashActivity">

    <intent-filter>

        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />

    </intent-filter>

</activity>

<activity android:name=".MainActivity" />

运行即可实现

2、ViewPager

通常使用ViewPager来做引导页的话,都是一屏一屏地展示,下面有若干个小点可以切换,指导用户如何使用APP,是ViewPager加上fragment来使用

3、ViewFlipper

ViewFlipper是安卓中分页滑动的一种组件,每一个滑动的item项就是view的控件

4、ScrollView

这个不是非常常见,在赶集网和墨迹天气APP中可以看到,通过水平滑动可以实现某种效果

Android引导页框架

AppIntro

guideshow:   github地址:https://github.com/javajavadog/guideshow

SlidingTutorial-Android   github地址:https://github.com/Cleveroad/slidingtutorial-android
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: