有的App当你第一次打开的是和常常会有引导页来描述一些App信息(功能,特点),当然也要做验证,验证第二次进入不进入引导页,直接进入App,此博客借助ViewPager来实现引导页, ViewPager类提供了多界面切换的新效果,是谷歌在3.0之后加入的新特性,所以需要引用android.support.v4.view.ViewPager。
效果:
imagepublic class NativeActivity extends AppCompatActivity {
private ViewPager viewPager;
private List<View> listImg;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//将屏幕设置为全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_ys);
initView();
}
private void initView() {
viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager(), showView()));
listImg = new ArrayList<View>();
listImg.add(findViewById(R.id.y1));
listImg.add(findViewById(R.id.y2));
listImg.add(findViewById(R.id.y3));
viewPager.setOnPageChangeListener(showPageChange);
}
ViewPager.OnPageChangeListener showPageChange = new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
for (int i = 0; i < listImg.size(); i++) {
if (i == arg0) {
listImg.get(arg0).setBackgroundResource(R.drawable.y_focused);
} else {
listImg.get(i).setBackgroundResource(R.drawable.y_normal);
}
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
};
private List<Fragment> showView() {
List<Fragment> listView = new ArrayList<Fragment>();
listView.add(new Fragment1());
listView.add(new Fragment2());
listView.add(new Fragment3());
return listView;
}
}
由于代码太多,完整代码未给出,源码直接下载即可
网友评论