Android引导页GudiesDemo

参考自https://github.com/javajavadog/guideshow
用到的jar包可以在https://github.com/javajavadog/guideshow/blob/master/jar/guideshowlib.jar下载
1.AndroidStudio新建项目,复制文件guideshowlib.jar(需要下载,参见第二行)到..\app\libs目录下,添加依赖compile files('libs/guideshowlib.jar')
Android引导页GudiesDemo_第1张图片
2.res文件夹下新建文件夹drawable-xxhdpi并复制五张背景和小圆点图片到该目录
用到的图片在https://github.com/javajavadog/guideshow/tree/master/GuideShowDemo/res/drawable-xxhdpi
Android引导页GudiesDemo_第2张图片
3.新建fragment_entry.xml布局文件
引导页第五张,点击确定按钮启动MainActivity活动


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/bg_page_05" />

    <Button
        android:id="@+id/btn_entry"
        android:layout_width="160dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|bottom"
        android:layout_marginBottom="120dp"
        android:text="@string/entry"/>

FrameLayout>

4.新建EntryFragment.java文件继承自Fragment注册onCreateView事件

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_entry, null);

        view.findViewById(R.id.btn_entry).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GuideActivity activity = (GuideActivity)getActivity();
                activity.entryApp();
                //会爆红,因为没有GuideActivity,不过没关系,下一步做完就好了
            }
        });
        return view;
    }

5.新建GuideActivity.java文件继承自AbsGuideActivity,
import com.chechezhi.ui.guide.AbsGuideActivity;
添加方法
Android引导页GudiesDemo_第3张图片

    @Override
    public List buildGuideContent() {
        // prepare the information for our guide
        List guideContent = new ArrayList();

        SinglePage page01 = new SinglePage();
        page01.mBackground = getResources().getDrawable(R.drawable.bg_page_01);

        guideContent.add(page01);

        SinglePage page02 = new SinglePage();
        page02.mBackground = getResources().getDrawable(R.drawable.bg_page_02);

        guideContent.add(page02);

        SinglePage page03 = new SinglePage();
        page03.mBackground = getResources().getDrawable(R.drawable.bg_page_03);

        guideContent.add(page03);

        SinglePage page04 = new SinglePage();
        page04.mBackground = getResources().getDrawable(R.drawable.bg_page_04);

        guideContent.add(page04);

        SinglePage page05 = new SinglePage();
        page05.mCustomFragment = new EntryFragment();
        guideContent.add(page05);

        return guideContent;
    }

    @Override
    public Bitmap dotDefault() {
        return BitmapFactory.decodeResource(getResources(), R.drawable.ic_dot_default);
    }

    @Override
    public Bitmap dotSelected() {
        return BitmapFactory.decodeResource(getResources(), R.drawable.ic_dot_selected);
    }

    @Override
    public boolean drawDot() {
        return true;
    }

    /**
     * You need provide an id to the pager. You could define an id in
     * values/ids.xml and use it.
     */
    @Override
    public int getPagerId() {
        return R.id.guide_container;
    }

    public void entryApp() {
        // Time to entry your app! We just finish the activity, replace it with
        // your code.
        finish();
        Intent i = new Intent(GuideActivity.this, MainActivity.class);
        startActivity(i);
    }

其中getPagerId()方法用到的guide_container在values/ids.xml中添加(需要新建xml文件)


<resources>
    <item name="guide_container" type="id"/>
resources>

6.AndroidManiFest.xml文件修改启动为GuideActivity,并添加MainActivity活动

    ...
        ".GuideActivity">
            
                "android.intent.action.MAIN" />

                "android.intent.category.LAUNCHER" />
            
        
        ".MainActivity" />
    

ok了。
效果:

demo在这里https://download.csdn.net/download/qq_37471298/10386644

你可能感兴趣的:(Android)