APP開發(fā)中,引導(dǎo)頁(yè)展示通常是必不可少的缆瓣,用來展示產(chǎn)品谤碳。github上有一個(gè)引導(dǎo)頁(yè)的庫(kù),個(gè)人感覺不錯(cuò)西疤,就拿來使用,地址:AppIntro
-
導(dǎo)入AppIntro庫(kù)的方法(兩種):
方法一: 到github上下載AppIntro休溶,解壓代赁,將library文件夾拷貝到自己項(xiàng)目的根目錄下扰她,重命名為app____intro____library,在settings.gradle文件中添加:include ':app',':app_____intro____library',在build.gradle文件中添加: compile project(':app_____intro____library')芭碍,重新編譯后即可使用徒役。
方法二: 直接在 build.gradle文件中添加如下代碼:
repositories {
mavenCentral()
}
dependencies {
compile 'com.github.paolorotolo:appintro:3.4.0'
}
- AppIntro的使用:
- 新建SlideFragment,展示介紹頁(yè)面窖壕,代碼如下:
package cn.studyou.parchment.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* 基本功能:引導(dǎo)頁(yè)Fragment
* 創(chuàng)建:王杰
* 創(chuàng)建時(shí)間:16/3/7
* 郵箱:w489657152@gmail.com
*/
public class SlideFragment extends Fragment {
private static final String ARG_LAYOUT_RES_ID = "layoutResId";
public static SlideFragment newInstance(int layoutResId) {
SlideFragment slideFragment = new SlideFragment();
Bundle args = new Bundle();
args.putInt(ARG_LAYOUT_RES_ID, layoutResId);
slideFragment.setArguments(args);
return slideFragment;
}
private int layoutResId;
public SlideFragment() {}
@Override
public void onCreate( Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getArguments() != null && getArguments().containsKey(ARG_LAYOUT_RES_ID))
layoutResId = getArguments().getInt(ARG_LAYOUT_RES_ID);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(layoutResId, container, false);
}
}
- 新建AppIntroActivity繼承自AppIntro忧勿,代碼如下:
package cn.studyou.parchment.activity;
import android.os.Bundle;
import com.github.paolorotolo.appintro.AppIntro;
import cn.studyou.parchment.R;
import cn.studyou.parchment.fragment.SlideFragment;
import cn.studyou.parchment.log.L;
import cn.studyou.parchment.utils.IntentUtil;
public class AppIntroActivity extends AppIntro {
@Override
public void init(Bundle savedInstanceState) {
addSlide(SlideFragment.newInstance(R.layout.intro1));
addSlide(SlideFragment.newInstance(R.layout.intro2));
addSlide(SlideFragment.newInstance(R.layout.intro3));
addSlide(SlideFragment.newInstance(R.layout.intro4));
setBarColor(getResources().getColor(R.color.green));
setSeparatorColor(getResources().getColor(R.color.colorAccent));
setVibrateIntensity(30);
setSkipText(getString(R.string.skip));
setDoneText(getString(R.string.enter));
}
private void startMain(){
startActivity(IntentUtil.getLauncherIntent().setClass(getApplicationContext(),MainActivity.class));
finish();
}
@Override
public void onSkipPressed() {
L.e("onSkipPressed");
startMain();
}
@Override
public void onDonePressed() {
L.e("onDonePressed");
startMain();
}
@Override
public void onSlideChanged() {
L.e("onSlideChanged");
}
@Override
public void onNextPressed() {
L.e("onNextPressed");
}
}
- R.layout.intro1布局文件是你想要展示的APP介紹的頁(yè)面。
- 啟動(dòng)APP設(shè)置跳轉(zhuǎn)到此Activity即可查看效果瞻讽。