Android开发之splash界面下详解及实例

现在刚下载的很多APP应用第一次打开都会在进入主界面之前有导航页,用来展示公司logo,或者推广自身这款APP。先上效果图:
Android开发之splash界面下详解及实例_第1张图片
Android开发之splash界面下详解及实例_第2张图片
Android开发之splash界面下详解及实例_第3张图片

首先解释一下:支持进入首页只能往右滑动,中间可以左右滑动,最后一张只能向前滑动,点击立即体验会进入主界面,点击跳过也会进入到主界面。接下来上代码。

1,在app/build.gradle中的闭包中加入:

compile 'cn.bingoogolapple:bga-banner:2.1.6@aar'
compile 'com.android.support:support-v4:24.1.0'

2,布局文件:activity_splash.xml。




  

    

    
  

  

  

3,逻辑代码,SplashActivity.java

package com.gyq.cloudreader;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import cn.bingoogolapple.bgabanner.BGABanner;

/**
 * 引导界面
 */
public class SplashActivity extends AppCompatActivity {
  private BGABanner mBackgroundBanner;
  private BGABanner mForegroundBanner;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    initView();

    initListener();

    processLogic();

  }

  private void initView() {
    mBackgroundBanner = (BGABanner)findViewById(R.id.banner_guide_background);
    mForegroundBanner = (BGABanner)findViewById(R.id.banner_guide_foreground);
  }

  private void initListener() {
    mForegroundBanner.setEnterSkipViewIdAndDelegate(R.id.btn_guide_enter, R.id.tv_guide_skip, new BGABanner.GuideDelegate() {
      @Override
      public void onClickEnterOrSkip() {
        startActivity(new Intent(SplashActivity.this, MainActivity.class));
        finish();
      }
    });

  }

  private void processLogic() {
    //设置数据源
    mBackgroundBanner.setData(R.drawable.uoko_guide_background_1,R.drawable.uoko_guide_background_2,R.drawable.uoko_guide_background_3);
    mForegroundBanner.setData(R.drawable.uoko_guide_foreground_1,R.drawable.uoko_guide_foreground_2,R.drawable.uoko_guide_foreground_3);
  }

  @Override
  protected void onResume() {
    super.onResume();

    // 如果开发者的引导页主题是透明的,需要在界面可见时给背景 Banner 设置一个白色背景,避免滑动过程中两个 Banner 都设置透明度后能看到 Launcher
    mBackgroundBanner.setBackgroundResource(android.R.color.white);
  }
}

小结:记得以前写一个这样的引导页,还需要自己手写半天,现在有开源啦!看上面的代码我想你应该已经知道了这个就是用的BGABanner来实现的。不过还有点小细节。

1,布局文件中的style=”@style/WrapWrap”,我们需要在values文件夹下新建一个styles_base.xml。




  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

还有styles.xml文件中添加如下代码,这样可以整个屏幕显示:



  
  

  
  

最后清单文件,注册SplashActivity是写如下代码。


      
        

        
      
    

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

你可能感兴趣的:(Android开发之splash界面下详解及实例)