基本操作引导页的实现

1.效果图

在这里插入图片描述

2.使用步骤

1.添加依赖

//新手使用引导
//    下面注释是为了忽略
    //noinspection GradleCompatible
    compileOnly 'com.android.support:appcompat-v7:25.3.1'
    implementation 'com.github.huburt-Hu:NewbieGuide:v2.4.0'

2.在布局中使用

/**
                 * 基本设置
                 */
                NewbieGuide.with(this)
                        .setLabel("page")//设置引导层标示区分不同引导层,必传!否则报错
                        .setOnGuideChangedListener(new OnGuideChangedListener() {//引导层显示监听
                            @Override
                            public void onShowed(Controller controller) {
                                Log.e(TAG, "NewbieGuide onShowed: ");
                                //引导层显示
                            }

                            @Override
                            public void onRemoved(Controller controller) {//引导层隐藏监听
                                Log.e(TAG, "NewbieGuide  onRemoved: ");
                                //引导层消失(多页切换不会触发)
                            }
                        })
                        .setOnPageChangedListener(new OnPageChangedListener() {//引导页切换监听
                            @Override
                            public void onPageChanged(int page) {
                                Log.e(TAG, "NewbieGuide  onPageChanged: " + page);
                                //引导页切换,page为当前页位置,从0开始
                            }
                        })
                        .alwaysShow(true)//是否每次都显示引导层,默认false,只显示一次
                        /**
                         * 添加引导页一
                         */
                        .addGuidePage(//添加一页引导页
                                GuidePage.newInstance()//创建一个实例
                                        .addHighLight(bt_content)//添加高亮的view
                                        .addHighLight(bt_content, HighLight.Shape.RECTANGLE)
                                        .setLayoutRes(R.layout.activity_text_style)//设置引导页布局
                                        .setOnLayoutInflatedListener(new OnLayoutInflatedListener() {//设置引导层字体
                                            @Override
                                            public void onLayoutInflated(View view, Controller controller) {
                                                //引导页布局填充后回调,用于初始化
                                                TextView tv = view.findViewById(R.id.textView2);
                                                tv.setText("我是动态设置的文本");
                                            }
                                        })
                                        /*.setEnterAnimation(enterAnimation)//进入动画
                                        .setExitAnimation(exitAnimation)//退出动画*/
                        )
                        /**
                         * 添加引导页二
                         */
                        .addGuidePage(
                                GuidePage.newInstance()
                                        .addHighLight(tvBottom, HighLight.Shape.RECTANGLE, 20)
                                        .setLayoutRes(R.layout.view_guide_custom) //引导页布局,点击跳转下一页或者消失引导层的控件id
                                        .setEverywhereCancelable(true)//是否点击任意地方跳转下一页或者消失引导层,默认true
//                                        .setBackgroundColor(getResources().getColor(R.color.colorAccent))//设置背景色,建议使用有透明度的颜色
                                        /*.setEnterAnimation(enterAnimation)//进入动画
                                        .setExitAnimation(exitAnimation)//退出动画*/
                        )
                        /**
                         * 展示
                         */
                        .show();//显示引导层(至少需要一页引导页才能显示)

3.全部代码

1.java

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.app.hubert.guide.NewbieGuide;
import com.app.hubert.guide.core.Controller;
import com.app.hubert.guide.listener.OnGuideChangedListener;
import com.app.hubert.guide.listener.OnLayoutInflatedListener;
import com.app.hubert.guide.listener.OnPageChangedListener;
import com.app.hubert.guide.model.GuidePage;
import com.app.hubert.guide.model.HighLight;

public class MainActivity2 extends AppCompatActivity implements View.OnClickListener {

    private Button bt_content;
    private String TAG = MainActivity2.class.getSimpleName();
    private Button tvBottom;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
    }

    private void initView() {
        bt_content = (Button) findViewById(R.id.bt_content);

        bt_content.setOnClickListener(this);
        tvBottom = (Button) findViewById(R.id.tvBottom);
        tvBottom.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_content:
                /**
                 * 基本设置
                 */
                NewbieGuide.with(this)
                        .setLabel("page")//设置引导层标示区分不同引导层,必传!否则报错
                        .setOnGuideChangedListener(new OnGuideChangedListener() {//引导层显示监听
                            @Override
                            public void onShowed(Controller controller) {
                                Log.e(TAG, "NewbieGuide onShowed: ");
                                //引导层显示
                            }

                            @Override
                            public void onRemoved(Controller controller) {//引导层隐藏监听
                                Log.e(TAG, "NewbieGuide  onRemoved: ");
                                //引导层消失(多页切换不会触发)
                            }
                        })
                        .setOnPageChangedListener(new OnPageChangedListener() {//引导页切换监听
                            @Override
                            public void onPageChanged(int page) {
                                Log.e(TAG, "NewbieGuide  onPageChanged: " + page);
                                //引导页切换,page为当前页位置,从0开始
                            }
                        })
                        .alwaysShow(true)//是否每次都显示引导层,默认false,只显示一次
                        /**
                         * 添加引导页一
                         */
                        .addGuidePage(//添加一页引导页
                                GuidePage.newInstance()//创建一个实例
                                        .addHighLight(bt_content)//添加高亮的view
                                        .addHighLight(bt_content, HighLight.Shape.RECTANGLE)
                                        .setLayoutRes(R.layout.activity_text_style)//设置引导页布局
                                        .setOnLayoutInflatedListener(new OnLayoutInflatedListener() {//设置引导层字体
                                            @Override
                                            public void onLayoutInflated(View view, Controller controller) {
                                                //引导页布局填充后回调,用于初始化
                                                TextView tv = view.findViewById(R.id.textView2);
                                                tv.setText("我是动态设置的文本");
                                            }
                                        })
                                        /*.setEnterAnimation(enterAnimation)//进入动画
                                        .setExitAnimation(exitAnimation)//退出动画*/
                        )
                        /**
                         * 添加引导页二
                         */
                        .addGuidePage(
                                GuidePage.newInstance()
                                        .addHighLight(tvBottom, HighLight.Shape.RECTANGLE, 20)
                                        .setLayoutRes(R.layout.view_guide_custom) //引导页布局,点击跳转下一页或者消失引导层的控件id
                                        .setEverywhereCancelable(true)//是否点击任意地方跳转下一页或者消失引导层,默认true
//                                        .setBackgroundColor(getResources().getColor(R.color.colorAccent))//设置背景色,建议使用有透明度的颜色
                                        /*.setEnterAnimation(enterAnimation)//进入动画
                                        .setExitAnimation(exitAnimation)//退出动画*/
                        )
                        /**
                         * 展示
                         */
                        .show();//显示引导层(至少需要一页引导页才能显示)
                break;
            case R.id.tvBottom:
                break;
        }
    }
}

2.xml

1.activity_main2

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity2">


    <Button
        android:id="@+id/bt_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="bt1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/tvBottom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/bt_content" />

    <TextView
        android:id="@+id/iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="TextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tvBottom" />
</androidx.constraintlayout.widget.ConstraintLayout>

2.activity_text_style

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TextStyleActivity3">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

3.view_guide_custom

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="我是傻逼二号"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值