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

Android开发之splash界面下详解及实例,第1张

概述现在刚下载的很多APP应用第一次打开都会在进入主界面之前有导航页,用来展示公司logo,或者推广自身这款APP。先上效果图:

现在刚下载的很多APP应用第一次打开都会在进入主界面之前有导航页,用来展示公司logo,或者推广自身这款APP。先上效果图:



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

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。

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"  xmlns:app="http://schemas.androID.com/apk/res-auto"  xmlns:tools="http://schemas.androID.com/tools"  androID:ID="@+ID/activity_splash"  androID:layout_wIDth="match_parent"  androID:layout_height="match_parent"  tools:context="com.gyq.cloudreader.SplashActivity">  <cn.bingoogolapple.bgabanner.BGAGuIDelinkageLayout >    <cn.bingoogolapple.bgabanner.BGABanner      androID:ID="@+ID/banner_guIDe_background"            app:banner_pageChangeDuration="1000"      app:banner_pointAutoplayAble="false"      app:banner_pointContainerBackground="@androID:color/transparent"      app:banner_pointDrawable="@drawable/bga_banner_selector_point_hollow"      app:banner_pointtopBottommargin="15dp"      app:banner_TransitionEffect="fade"/>    <cn.bingoogolapple.bgabanner.BGABanner      androID:ID="@+ID/banner_guIDe_foreground"            app:banner_pageChangeDuration="1000"      app:banner_pointAutoplayAble="false"      app:banner_pointContainerBackground="@androID:color/transparent"      app:banner_pointDrawable="@drawable/bga_banner_selector_point_hollow"      app:banner_pointtopBottommargin="15dp"      app:banner_TransitionEffect="Alpha"/>  </cn.bingoogolapple.bgabanner.BGAGuIDelinkageLayout>  <TextVIEw    androID:ID="@+ID/tv_guIDe_skip"        androID:layout_alignParentRight="true"    androID:layout_marginRight="8dp"    androID:layout_margintop="8dp"    androID:clickable="true"    androID:padding="4dp"    androID:text="跳过 >"    androID:textcolor="@androID:color/white"    androID:textSize="16sp"/>  <button    androID:ID="@+ID/btn_guIDe_enter"        androID:layout_alignParentBottom="true"    androID:layout_centerHorizontal="true"    androID:layout_marginBottom="60dp"    androID:background="@drawable/selector_btn_test"    androID:padding="10dp"    androID:text="立即体验"    androID:textcolor="@androID:color/white"    androID:textSize="20sp"    androID:visibility="gone"    tools:visibility="visible"/></relativeLayout>

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。

<?xml version="1.0" enCoding="utf-8"?><resources xmlns:androID="http://schemas.androID.com/apk/res/androID">  <style name="WrapMatch">    <item name="androID:layout_wIDth">wrap_content</item>    <item name="androID:layout_height">match_parent</item>  </style>  <style name="MatchWrap">    <item name="androID:layout_wIDth">match_parent</item>    <item name="androID:layout_height">wrap_content</item>  </style>  <style name="WrapWrap">    <item name="androID:layout_wIDth">wrap_content</item>    <item name="androID:layout_height">wrap_content</item>  </style>  <style name="MatchMatch">    <item name="androID:layout_wIDth">match_parent</item>    <item name="androID:layout_height">match_parent</item>  </style>  <style name="Matchauto">    <item name="androID:layout_wIDth">match_parent</item>    <item name="androID:layout_weight">1</item>    <item name="androID:layout_height">0dp</item>  </style>  <style name="autoMatch">    <item name="androID:layout_wIDth">0dp</item>    <item name="androID:layout_weight">1</item>    <item name="androID:layout_height">match_parent</item>  </style>  <style name="Wrapauto">    <item name="androID:layout_wIDth">wrap_content</item>    <item name="androID:layout_weight">1</item>    <item name="androID:layout_height">0dp</item>  </style>  <style name="autoWrap">    <item name="androID:layout_wIDth">0dp</item>    <item name="androID:layout_weight">1</item>    <item name="androID:layout_height">wrap_content</item>  </style>  <style name="WrapMatch.Vertical">    <item name="androID:orIEntation">vertical</item>  </style>  <style name="WrapMatch.Horizontal">    <item name="androID:orIEntation">horizontal</item>  </style>  <style name="MatchWrap.Vertical">    <item name="androID:orIEntation">vertical</item>  </style>  <style name="MatchWrap.Horizontal">    <item name="androID:orIEntation">horizontal</item>  </style>  <style name="WrapWrap.Vertical">    <item name="androID:orIEntation">vertical</item>  </style>  <style name="WrapWrap.Horizontal">    <item name="androID:orIEntation">horizontal</item>  </style>  <style name="MatchMatch.Vertical">    <item name="androID:orIEntation">vertical</item>  </style>  <style name="MatchMatch.Horizontal">    <item name="androID:orIEntation">horizontal</item>  </style>  <style name="Matchauto.Vertical">    <item name="androID:orIEntation">vertical</item>  </style>  <style name="Matchauto.Horizontal">    <item name="androID:orIEntation">horizontal</item>  </style>  <style name="autoMatch.Vertical">    <item name="androID:orIEntation">vertical</item>  </style>  <style name="autoMatch.Horizontal">    <item name="androID:orIEntation">horizontal</item>  </style>  <style name="Wrapauto.Vertical">    <item name="androID:orIEntation">vertical</item>  </style>  <style name="Wrapauto.Horizontal">    <item name="androID:orIEntation">horizontal</item>  </style>  <style name="autoWrap.Vertical">    <item name="androID:orIEntation">vertical</item>  </style>  <style name="autoWrap.Horizontal">    <item name="androID:orIEntation">horizontal</item>  </style>  <style name="MatchOne">    <item name="androID:layout_wIDth">match_parent</item>    <item name="androID:layout_height">1px</item>  </style>  <style name="OneMatch">    <item name="androID:layout_wIDth">1px</item>    <item name="androID:layout_height">match_parent</item>  </style></resources>

还有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="Apptheme.Splash">    <item name="windowActionbar">false</item>    <item name="windowNoTitle">true</item>    <item name="androID:windowBackground">@androID:color/transparent</item>    <item name="androID:colorBackgroundCacheHint">@null</item>    <item name="androID:windowIsTranslucent">true</item>    <item name="androID:windowFullscreen">true</item>    <item name="androID:windowContentOverlay">@null</item>  </style></resources>

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

<activity androID:name=".SplashActivity"      androID:label="@string/app_name"      androID:screenorIEntation="portrait"      androID:theme="@style/Apptheme.Splash">      <intent-filter>        <action androID:name="androID.intent.action.MAIN" />        <category androID:name="androID.intent.category.LAUNCHER" />      </intent-filter>    </activity>

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

总结

以上是内存溢出为你收集整理的Android开发之splash界面下详解实例全部内容,希望文章能够帮你解决Android开发之splash界面下详解及实例所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存