Android開發(fā)之splash界面下詳解及實(shí)例
現(xiàn)在剛下載的很多APP應(yīng)用第一次打開都會在進(jìn)入主界面之前有導(dǎo)航頁,用來展示公司logo,或者推廣自身這款A(yù)PP。先上效果圖:

首先解釋一下:支持進(jìn)入首頁只能往右滑動,中間可以左右滑動,最后一張只能向前滑動,點(diǎn)擊立即體驗(yàn)會進(jìn)入主界面,點(diǎn)擊跳過也會進(jìn)入到主界面。接下來上代碼。
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 style="@style/MatchMatch">
<cn.bingoogolapple.bgabanner.BGABanner
android:id="@+id/banner_guide_background"
style="@style/MatchMatch"
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"
style="@style/MatchMatch"
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"
style="@style/WrapWrap"
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"
style="@style/WrapWrap"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="60dp"
android:background="@drawable/selector_btn_test"
android:padding="10dp"
android:text="立即體驗(yàn)"
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;
/**
* 引導(dǎo)界面
*/
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() {
//設(shè)置數(shù)據(jù)源
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();
// 如果開發(fā)者的引導(dǎo)頁主題是透明的,需要在界面可見時(shí)給背景 Banner 設(shè)置一個白色背景,避免滑動過程中兩個 Banner 都設(shè)置透明度后能看到 Launcher
mBackgroundBanner.setBackgroundResource(android.R.color.white);
}
}
小結(jié):記得以前寫一個這樣的引導(dǎo)頁,還需要自己手寫半天,現(xiàn)在有開源啦!看上面的代碼我想你應(yīng)該已經(jīng)知道了這個就是用的BGABanner來實(shí)現(xiàn)的。不過還有點(diǎn)小細(xì)節(jié)。
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>
<!--避免第一次進(jìn)來白屏或黑屏-->
<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>
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
Android 判斷網(wǎng)絡(luò)狀態(tài)及開啟網(wǎng)路
這篇文章主要介紹了Android 判斷網(wǎng)絡(luò)狀態(tài)及開啟網(wǎng)路的相關(guān)資料,在開發(fā)網(wǎng)路狀態(tài)的時(shí)候需要先判斷是否開啟之后在提示用戶進(jìn)行開啟操作,需要的朋友可以參考下2017-08-08
android設(shè)備間實(shí)現(xiàn)無線投屏的示例代碼
Android提供了MediaProjection來實(shí)現(xiàn)錄屏,通過MediaProjection可以獲取當(dāng)前屏幕的視頻流,而視頻流需要通過編解碼來壓縮進(jìn)行傳輸,通過MediaCodec可實(shí)現(xiàn)視頻的編碼和解碼,這篇文章主要介紹了android設(shè)備間實(shí)現(xiàn)無線投屏,需要的朋友可以參考下2022-06-06
點(diǎn)擊微信內(nèi)網(wǎng)頁a標(biāo)簽直接跳轉(zhuǎn)打開淘寶APP的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于如何實(shí)現(xiàn)點(diǎn)擊微信內(nèi)網(wǎng)頁a標(biāo)簽直接跳轉(zhuǎn)打開淘寶APP的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。2017-11-11
Android實(shí)現(xiàn)listview滑動時(shí)漸隱漸現(xiàn)頂部欄實(shí)例代碼
android中實(shí)現(xiàn)listview滑動時(shí)漸隱漸現(xiàn)頂部欄只是在獲取listview的滑動距離上可能沒法直接獲取,需要動態(tài)的去計(jì)算。感興趣的朋友一起看看吧2016-10-10
Android實(shí)現(xiàn)斷點(diǎn)續(xù)傳功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)斷點(diǎn)續(xù)傳功能,能在上次的斷點(diǎn)處繼續(xù)上傳,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07
Android編程設(shè)計(jì)模式之原型模式實(shí)例詳解
這篇文章主要介紹了Android編程設(shè)計(jì)模式之原型模式,結(jié)合實(shí)例形式詳細(xì)分析了Android設(shè)計(jì)模式之原型模式的概念、原理、定義、使用方法及相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-12-12
Android實(shí)現(xiàn)Ant Design 自定義表單組件
Ant Design 組件提供了Input,InputNumber,Radio,Select,uplod等表單組件,下面通過本文給大家詳細(xì)介紹Android實(shí)現(xiàn)Ant Design 自定義表單組件,需要的的朋友參考下吧2017-06-06

