一行代码接入Android app指引
demo中又参考例子,这里简单概括一下
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
}
}
// 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)
...
}
guideManager.show()
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()