APP开发中,引导页展示通常是必不可少的,用来展示产品。github上有一个引导页的库,个人感觉不错,就拿来使用,地址:AppIntro
-
导入AppIntro库的方法(两种):
-
方法一: 到github上下载AppIntro,解压,将library文件夹拷贝到自己项目的根目录下,重命名为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,展示介绍页面,代码如下:
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;
/**
* 基本功能:引导页Fragment
* 创建:王杰
* 创建时间: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介绍的页面。
- 启动APP设置跳转到此Activity即可查看效果。
网友评论