引导页高亮小提示

2024-08-31 22:58
文章标签 引导 高亮 小提示

本文主要是介绍引导页高亮小提示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这里写图片描述这里写图片描述
这里写图片描述这里写图片描述

布局省略

测试代码入下:

  HighLightGuideView.builder(this).addHighLightGuidView(confirm, R.mipmap.unchain).setHighLightStyle(HighLightGuideView.VIEWSTYLE_RECT).show();HighLightGuideView.builder(this).addHighLightGuidView(confirm, R.mipmap.unchain).setHighLightStyle(HighLightGuideView.VIEWSTYLE_CIRCLE).show();
//HighLightGuideView.builder(this).addHighLightGuidView(confirm, R.mipmap.unchain).setHighLightStyle(HighLightGuideView.VIEWSTYLE_OVAL).show();HighLightGuideView.builder(this).addHighLightGuidView(setting_feedback_text, R.mipmap.input_pass).setHighLightStyle(HighLightGuideView.VIEWSTYLE_NO).show();

参数的意思是:
addHighLightGuidView为哪个控件设置高亮,以及在该控件处填指示的图片
setHighLightStyle设置高亮的类型–矩形、圆形、椭圆、以及没有高亮

HighLightGuideView

package com.safly.myapplication.highlight;import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;import com.safly.myapplication.R;import java.util.ArrayList;/*** * des:“应用新功能”的用户指引view*/
public class HighLightGuideView extends View {//高亮类型:矩形、圆形、椭圆、没有高亮public static final int VIEWSTYLE_RECT = 0;public static final int VIEWSTYLE_CIRCLE = 1;public static final int VIEWSTYLE_OVAL = 2;public static final int VIEWSTYLE_NO = -1;//画笔类型,圆滑、默认public int maskblurstyle = MASKBLURSTYLE_SOLID;//画笔类型默认public static final int MASKBLURSTYLE_SOLID = 0;public static final int MASKBLURSTYLE_NORMAL = 1;private View rootView;//activity的contentview,是FrameLayoutprivate Bitmap inputPass, addEvent, unChain;// 指示箭头private Bitmap fgBitmap;// 前景private Canvas mCanvas;// 绘制蒙版层的画布private Paint mPaint;// 绘制蒙版层画笔private int screenW, screenH;// 屏幕宽高private int radius;//圆半径private OnDismissListener onDismissListener;//关闭监听private Activity activity;/*******************可配置属性*****************************/private boolean touchOutsideCancel = true;//外部点击是否可关闭private int highLightStyle = VIEWSTYLE_RECT;//高亮类型默认圆形private ArrayList<Bitmap> tipBitmaps;//显示图片private ArrayList<View> targetViews;//高亮目标viewprivate int maskColor = 0x99000000;// 蒙版层颜色private int borderWitdh = 2;private int highLisghtPadding = 0;// 高亮控件paddingprivate int mipTipsId;private HighLightGuideView(Activity activity) {super(activity);this.activity=activity;cal(activity);init(activity);}public static HighLightGuideView builder(Activity activity) {return new HighLightGuideView(activity);}/*** 获取屏幕的宽度、高度* @param context*/private void cal(Context context) {int[] screenSize = UiUtil.getScreenSize((Activity) context);screenW = screenSize[0];screenH = screenSize[1];}private void init(Context context) {tipBitmaps = new ArrayList<>();targetViews = new ArrayList<>();rootView = ((Activity) getContext()).findViewById(android.R.id.content);addEvent = BitmapFactory.decodeResource(getResources(), R.mipmap.add_event);inputPass = BitmapFactory.decodeResource(getResources(), R.mipmap.input_pass);unChain = BitmapFactory.decodeResource(getResources(), R.mipmap.unchain);BlurMaskFilter.Blur blurStyle = null;switch (maskblurstyle) {case MASKBLURSTYLE_SOLID:blurStyle = BlurMaskFilter.Blur.SOLID;break;case MASKBLURSTYLE_NORMAL:blurStyle = BlurMaskFilter.Blur.NORMAL;break;}mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);// 设置画笔透明度为0是关键!mPaint.setARGB(0, 255, 0, 0);mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));mPaint.setMaskFilter(new BlurMaskFilter(0.1f, blurStyle));//蒙层mapfgBitmap = Bitmap.createBitmap(screenW, screenH, Bitmap.Config.ARGB_4444);mCanvas = new Canvas(fgBitmap);mCanvas.drawColor(maskColor);}@Overrideprotected void onDraw(Canvas canvas) {if (targetViews == null && tipBitmaps == null)return;// 绘制前景DST_IN!!!!!!!!!canvas.drawBitmap(fgBitmap, 0, 0, null);//有高亮控件if (targetViews.size() > 0 && tipBitmaps.size() > 0) {for (int i = 0; i < targetViews.size(); i++) {//高亮控件宽高int vWidth = targetViews.get(i).getWidth();int vHeight = targetViews.get(i).getHeight();//获取获取高亮控件坐标int left = 0;int top = 0;int right = 0;int bottom = 0;try {Rect rtLocation =ViewUtils.getLocationInView(((ViewGroup)activity.findViewById(Window.ID_ANDROID_CONTENT)).getChildAt(0),targetViews.get(i));left = rtLocation.left;top = rtLocation.top;right = rtLocation.right;bottom = rtLocation.bottom;Log.d("statusheightssleft",left+"");Log.d("statusheightsstop",top+"");Log.d("statusheightbottom",right+"");Log.d("statusheightsbottom",bottom+"");} catch (Exception e) {e.printStackTrace();}//绘制高亮形状switch (highLightStyle) {case VIEWSTYLE_OVAL:RectF rectf = new RectF(left-highLisghtPadding, top-highLisghtPadding, right+highLisghtPadding, bottom+highLisghtPadding);mCanvas.drawOval(rectf, mPaint);break;case VIEWSTYLE_RECT:RectF rect = new RectF(left - borderWitdh-highLisghtPadding, top - borderWitdh-highLisghtPadding, right + borderWitdh+highLisghtPadding, bottom + borderWitdh+highLisghtPadding);mCanvas.drawRoundRect(rect, 20, 20, mPaint);break;case VIEWSTYLE_CIRCLE:radius = vWidth > vHeight ? vWidth / 2 +highLisghtPadding/2: vHeight / 2+ highLisghtPadding/2;if (radius < 50) {radius = 100;}mCanvas.drawCircle(left + vWidth / 2, top + vHeight / 2, radius, mPaint);break;}//绘制箭头和提示图switch (mipTipsId){case R.mipmap.add_event:mCanvas.drawBitmap(addEvent, left + vWidth / 2 - 50, bottom, null);break;case R.mipmap.input_pass:mCanvas.drawBitmap(inputPass, left, top, null);break;case R.mipmap.unchain:int width = unChain.getWidth();mCanvas.drawBitmap(unChain,  screenW - width - radius, bottom, null);break;default:break;}}}}@Overridepublic boolean onTouchEvent(MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_UP://if (touchOutsideCancel) {this.setVisibility(View.GONE);//移除viewif (rootView != null) {((ViewGroup) rootView).removeView(this);}//返回监听if (this.onDismissListener != null) {onDismissListener.onDismiss();}return true;}break;}return true;}public interface OnDismissListener {public void onDismiss();}/********************builder模式设置属性******************************//*** 绘制前景画布颜色** @param bgColor*/public HighLightGuideView setMaskColor(int bgColor) {try {this.maskColor = ContextCompat.getColor(getContext(),bgColor);// 重新绘制前景画布mCanvas.drawColor(maskColor);} catch (Exception e) {e.printStackTrace();}return this;}/*** 设置高亮显示类型** @param style*/public HighLightGuideView setHighLightStyle(int style) {this.highLightStyle = style;return this;}/*** 设置高亮画笔类型** @param maskblurstyle*/public HighLightGuideView setMaskblurstyle(int maskblurstyle) {this.maskblurstyle = maskblurstyle;return this;}/*** 设置需要高亮的View和提示的图片** @param targetView* @param res*/public HighLightGuideView addHighLightGuidView(View targetView, int res) {try {mipTipsId = res;targetViews.add(targetView);tipBitmaps.add(BitmapFactory.decodeResource(getResources(), res));} catch (Exception e) {e.printStackTrace();}return this;}/*** 设置不需要高亮的View,只是提示图片** @param res*/public HighLightGuideView addNoHighLightGuidView(int res) {try {tipBitmaps.add(BitmapFactory.decodeResource(getResources(), res));} catch (Exception e) {e.printStackTrace();}return this;}/*** 设置外部是否关闭,默认关闭** @param cancel*/public HighLightGuideView setTouchOutsideDismiss(boolean cancel) {this.touchOutsideCancel = cancel;return this;}/*** 设置额外的边框宽度** @param borderWidth*/public HighLightGuideView setBorderWidth(int borderWidth) {this.borderWitdh = borderWidth;return this;}/*** 设置状态栏高度 默认是减去了一个状态栏高度 如果主题设置android:windowTranslucentStatus=true* 需要设置状态栏高度为0** @param highLisghtPadding*/public HighLightGuideView setHighLisghtPadding(int highLisghtPadding) {this.highLisghtPadding = highLisghtPadding;return this;}/*** 设置关闭监听** @param listener*/public HighLightGuideView setOnDismissListener(OnDismissListener listener) {this.onDismissListener = listener;return this;}/*** 清空画布*/public HighLightGuideView clearBg() {if (mCanvas != null) {Paint paint = new Paint();paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));mCanvas.drawPaint(paint);paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));}// 将其注入画布mCanvas = new Canvas(fgBitmap);// 绘制前景画布mCanvas.drawColor(maskColor);return this;}/*** 显示*/public void show() {if (rootView != null) {ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);((ViewGroup) rootView).addView(this, ((ViewGroup) rootView).getChildCount(), lp);}}}

UiUtil

package com.safly.myapplication.highlight;import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;/*** * des:测量工具类*/
public final class UiUtil {/*** 获取屏幕尺寸* * @param activity*            Activity* @return 屏幕尺寸像素值,下标为0的值为宽,下标为1的值为高*/public static int[] getScreenSize(Activity activity) {DisplayMetrics metrics = new DisplayMetrics();activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);return new int[] { metrics.widthPixels, metrics.heightPixels };}/*** 获取状态栏高度* @param context* @return*/public static int getStatusBarHeight(Context context) {int result = 0;int resId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");if (resId > 0) {result = context.getResources().getDimensionPixelOffset(resId);}return result;}}

ViewUtils

package com.safly.myapplication.highlight;import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.view.View;/*** * des:测量位置*/
public class ViewUtils {private static final String FRAGMENT_CON = "NoSaveStateFrameLayout";public static Rect getLocationInView(View parent, View child) {if (child == null || parent == null) {throw new IllegalArgumentException("parent and child can not be null .");}View decorView = null;Context context = child.getContext();if (context instanceof Activity) {decorView = ((Activity) context).getWindow().getDecorView();}Rect result = new Rect();Rect tmpRect = new Rect();View tmp = child;if (child == parent) {child.getHitRect(result);return result;}while (tmp != decorView && tmp != parent) {//找到控件占据的矩形区域的矩形坐标tmp.getHitRect(tmpRect);if (!tmp.getClass().equals(FRAGMENT_CON)) {result.left += tmpRect.left;result.top += tmpRect.top;}tmp = (View) tmp.getParent();}result.right = result.left + child.getMeasuredWidth();result.bottom = result.top + child.getMeasuredHeight();return result;}
}

这篇关于引导页高亮小提示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1125234

相关文章

Android 引导图层、引导页

Android 引导图层(参考gith项目) Android 引导图层参考gith项目 简介不多说 先上图 部分代码说明 简介: 最最轻量级的新手引导图层库,支持单页,多个引导,支持设置不同的图形,支持动画等,例如:Activity 、fragment、各种对应View 皆可; 不多说 先上图: OK ;可以根据自己的需求重新定义 显示的效果;都

linux-5.6.6 内核引导

本文转自网络文章,内容均为非盈利,版权归原作者所有。 转载此文章仅为个人收藏,分享知识,如有侵权,马上删除。 原文作者:povcfe 原文地址:https://bbs.pediy.com/thread-261718.htm     本文详细讲解linux内核的加载过程,参考linux-insiders,并结合linux-5.6.6代码对原文的部分老旧内容做修改 引导 1.按

【Unity小技巧】URP管线遮挡高亮效果

前言 在URP渲染管线环境下实现物体遮挡高亮显示效果,效果如下: Unity URP遮挡高亮 实现步骤 创建层级,为需要显示高亮效果的物体添加层级,比如Player 创建一个材质球,也就是高亮效果显示的材质球找到Universal Renderer Data Assets 4.在Assets上添加两个Render Objects组件 第一个做如下三处设置 指定遮挡层级指

win10 gpt分区+uefi引导 卸载双系统ubuntu

1、首先暴力卸载ubuntu 在win10里面磁盘管理中找到对应的linux磁盘分区 删除卷OK 2、重启 出现下面(根据机型不同界面可能不一样 ) 3、exit 退出grub引导 进入uefi引导  选择win10引导项 (当然你要是一直按着进入bios boot的那个按键的话 也不用看第二步了 直接选择windows启动项进去 dell的话是F12) 4、进入

【硬刚ES】ES入门 (13)Java API 操作(4)DQL(1) 请求体查询/term 查询,查询条件为关键字/分页查询/数据排序/过滤字段/Bool 查询/范围查询/模糊查询/高亮查询/聚合查

本文是对《【硬刚大数据之学习路线篇】从零到大数据专家的学习指南(全面升级版)》的ES部分补充。 1 请求体查询 2 高亮查询 3 聚合查询 package com.atguigu.es.test;import org.apache.http.HttpHost;import org.apache.lucene.search.TotalHits;import org.elasticse

Learning Memory-guided Normality for Anomaly Detection——学习记忆引导的常态异常检测

又是一篇在自编码器框架中研究使用记忆模块的论文,可以看做19年的iccv的论文的衍生,在我的博客中对19年iccv这篇论文也做了简单介绍。韩国人写的,应该是吧,这名字听起来就像。 摘要abstract 我们解决异常检测的问题,即检测视频序列中的异常事件。基于卷积神经网络的异常检测方法通常利用代理任务(如重建输入视频帧)来学习描述正常情况的模型,而在训练时看不到异常样本,并在测试时使用重建误

基于中心引导判别学习的弱监督视频异常检测

WEAKLY SUPERVISED VIDEO ANOMALY DETECTION VIA CENTER-GUIDED DISCRIMINATIVE LEARNING 基于中心引导判别学习的弱监督视频异常检测 abstract 由于异常视频内容和时长的多样性,监控视频中的异常检测是一项具有挑战性的任务。在本文中,我们将视频异常检测看作是一个弱监督下视频片段异常分数的回归问题。因此,我们提出了

Element-ui设置table 选中某行高亮自定义背景色

Element-ui设置table 选中某行高亮自定义背景色 在el-table标签中添加单选 highlight-current-row <el-table highlight-current-row @row-click="mainBodySelectionChange"></el-table> 在style中设置颜色 /* 设置当前页面element全局table 选中某行时的背景色

C1-2 ABB二次SDK开发——手把手教登录对应的机器人控制器(图片引导操作)登录机器人控制器和刷新机器人列表

1.完成配置后我们开始进行操作 C1-1 ABB二次SDK开发——C#Window窗体-环境配置(带ABB二次开发SDK资源包)-CSDN博客文章浏览阅读95次。3.记住路径,右键C#引用,然后导入ABB.Robotics.Controllers.PC.dll。2.安装资源文件PCABB二次开发的SDK,并打开安装路径。1.新建VSC#的windowfrom项目。4.在框架代码主界面代码中添加。

uni-app 指定内容高亮

插件地址:https://ext.dcloud.net.cn/plugin?id=735 预览效果: 作者:黄河爱浪 QQ:1846492969,邮箱:helang.love@qq.com 公众号:web-7258,本文原创,著作权归作者所有,转载请注明原链接及出处。 更多精彩文章,请扫下方二维码关注我的公众号