Giter VIP home page Giter VIP logo

guideview's Introduction

GuideView

一行代码接入Android app指引

如何接入?

demo中又参考例子,这里简单概括一下

1. 创建GuideManager实例,并设置指引回调

val guideManager = GuideManager(activity)
guideManager.mGuideListener = object: GuideListener {
    override fun onNextStep(step: Int) {
        Toast.makeText(context, "当前步骤:${step + 1}", Toast.LENGTH_SHORT).show()
    }

    override fun onCompleted() {
        tvShowGuide.visibility = View.VISIBLE
    }
}

2. 创建指引步骤实例 GuideInfo,并添加到GuideManager

// imgLogo is the view you want to heighlight
val guideStep1 = GuideInfo(imgLogo, isOval = true).apply {
    val textShape = TextDecoration(
        "这是圆形高亮区域,点击高亮进入下一步",
        sp2px(context, 12F).toFloat(),
        ContextCompat.getColor(context, R.color.white),
        targetBound.right, targetBound.centerY()
    )
    addShape(textShape)
}
val guideStep2 = ...
val guideStep3 = ...
...
guideManager.apply{
    addGuideStep(guideStep1)
    addGuideStep(guideStep2)
    addGuideStep(guideStep3)
    ...
}

3. 显示指引

guideManager.show()

4. 完整代码如下

GuideManager(activity).apply {
    addGuideStep(GuideInfo(imgLogo, isOval = true).apply {
        val textShape = TextDecoration(
            "这是圆形高亮区域,点击高亮进入下一步",
            sp2px(context, 12F).toFloat(),
            ContextCompat.getColor(context, R.color.white),
            targetBound.right + dip2px(context, 8F), targetBound.centerY()
        )
        addShape(textShape)
    })
    addGuideStep(GuideInfo(imgLogo2, radius = 16F).apply {
        val textShape = TextDecoration(
            "这是圆角矩形高亮区域,点击高亮继续进入下一步",
            sp2px(context, 12F).toFloat(),
            ContextCompat.getColor(context, R.color.white),
            targetBound.left, targetBound.bottom + dip2px(context, 24F)
        )
        addShape(textShape)
    })
    addGuideStep(GuideInfo(tvName, padding = 20).apply {
        val bitmap = BitmapFactory.decodeResource(resources, R.mipmap.ic_add_location_white_48dp)
        val bitmapShape =
            BitmapDecoration(
                bitmap,
                targetBound.left,
                targetBound.top - dip2px(context, 45F)
            )
        addShape(bitmapShape)
        val textShape = TextDecoration(
            "点击高亮结束指引",
            sp2px(context, 14F).toFloat(),
            ContextCompat.getColor(context, R.color.white),
            targetBound.centerX(),
            targetBound.bottom + dip2px(context, 32F)
        )
        addShape(textShape)
    })
    mGuideListener = object: GuideListener {
        override fun onNextStep(step: Int) {
            Toast.makeText(context, "当前步骤:${step + 1}", Toast.LENGTH_SHORT).show()
        }

        override fun onCompleted() {
            tvShowGuide.visibility = View.VISIBLE
        }
    }
    // 如果要显示“上一步”,“下一步”,可以设置GuideManager中的mGuideDialog,
}.show()

guideview's People

Contributors

hbottle avatar

Stargazers

HuangYueFeng avatar Layoute avatar Jim avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.