iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android MarkTipsView文字标识控件使用方法
  • 514
分享到

Android MarkTipsView文字标识控件使用方法

2024-04-02 19:04:59 514人浏览 八月长安
摘要

本文实例为大家分享了Android MarkTipsView文字标识控件的具体代码,供大家参考,具体内容如下 效果预览 使用 使用方式跟TextView使用方式一样,背景设置直接s

本文实例为大家分享了Android MarkTipsView文字标识控件的具体代码,供大家参考,具体内容如下

效果预览

使用

使用方式跟TextView使用方式一样,背景设置直接setBackgroundColor

源码


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;

import androidx.appcompat.widget.AppCompatTextView;


public class MarkTipsView extends AppCompatTextView {

    
    private Paint paint;
    
    private int width;
    
    private int height;
    
    private int markWidth = 12;
    
    private int markHeight = 12;
    
    private float radius = 10;
    
    private int solid = Color.parseColor("#F1AA44");

    public MarkTipsView(Context context) {
        super(context);
        initAttributeSet(context, null);
    }

    public MarkTipsView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initAttributeSet(context, attrs);
    }

    public MarkTipsView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initAttributeSet(context, attrs);
    }

    private void initAttributeSet(Context context, AttributeSet attrs) {
        paint = new Paint();
        paint.setDither(true);
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.FILL);
        TypedArray array = context.obtainStyledAttributes(attrs,new int[]{android.R.attr.background});
        solid =  array.getInt(0,solid);
        array.recycle();
    }

    @Override
    public void setBackgroundColor(int color) {
        solid = color;
        invalidate();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        width = getMeasuredWidth();
        height = getMeasuredHeight();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom() + markHeight);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        paint.setColor(solid);
        //矩形
        Path path = new Path();
        RectF rect = new RectF(0, 0, width, height - markHeight);
        path.addRoundRect(rect, radius, radius, Path.Direction.CCW);
        //三角形
        Path onePath = new Path();
        onePath.lineTo(width / 2 - markWidth, rect.height());
        onePath.lineTo(width / 2, height);
        onePath.lineTo(width / 2 + markWidth, rect.height());
        onePath.close();
        path.addPath(onePath);
        //绘制路径
        canvas.drawPath(path, paint);
        super.onDraw(canvas);
        //重绘文字
        setText(getText());
    }

    
    public int getMarkHeight() {
        return markHeight;
    }

    
    public void setMarkHeight(int markHeight) {
        this.markHeight = markHeight;
        invalidate();
    }

    
    public int getMarkWidth() {
        return markWidth;
    }

    
    public void setMarkWidth(int markWidth) {
        this.markWidth = markWidth;
        invalidate();
    }

    
    public float getRadius() {
        return radius;
    }

    
    public void setRadius(float radius) {
        this.radius = radius;
        invalidate();
    }

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: Android MarkTipsView文字标识控件使用方法

本文链接: https://www.lsjlt.com/news/123766.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android MarkTipsView文字标识控件使用方法
    本文实例为大家分享了Android MarkTipsView文字标识控件的具体代码,供大家参考,具体内容如下 效果预览 使用 使用方式跟TextView使用方式一样,背景设置直接s...
    99+
    2024-04-02
  • Android控件RadioButton的使用方法
    本文实例为大家分享了Android控件RadioButton的使用代码,供大家参考,具体内容如下 内容 <?xml version="1.0" encoding=...
    99+
    2024-04-02
  • Android控件View的文字周围添加图标
    在Android控件View的文字周围添加图标,供大家参考,具体内容如下 在控件TextView文字周围放置图片(基于TextView的Button也能实现),减少多布局组合嵌套。 ...
    99+
    2024-04-02
  • Android控件AppWidgetProvider使用方法详解
    介绍AppWidgetProvider是Android中提供的用于实现桌面小工具的类,其本质是一个广播,即BroadcastReceiver,在实际的使用中,把AppWidgetProvider当成一个BroadcastReceiver即可...
    99+
    2023-05-30
    android appwidgetprovider pp
  • Android TextView文字使用字体的3种方法
    Android给文字添加字体效果有3种方法: 直接在xml布局里面添加 先将字体文件复制到该位置  然后在xml中引用该文件 在activity里面设置(1)  先将字体文件复制到该位置 然后在activity里面设置该字体 Type...
    99+
    2023-09-23
    android
  • Android SearchView搜索控件使用方法详解
    本文实例为大家分享了Android SearchView搜索控件的具体实现代码,供大家参考,具体内容如下 方法介绍 setQueryHint 设置 Hint 的文字内容 setMax...
    99+
    2024-04-02
  • Android基础控件RadioGroup使用方法详解
    RadioGroup是Android中的一个基础控件,用于实现一组单选按钮,同一时间只能选择一个单选按钮。RadioGroup的使用...
    99+
    2023-08-08
    Android
  • Android使用createNewFile()方法创建文件
    在Android中,使用`createNewFile()`方法可以创建一个新文件。以下是一种常见的使用方法:```javaFile ...
    99+
    2023-09-16
    android
  • 在Android控件View文字周围添加图标的示例
    这篇文章将为大家详细讲解有关在Android控件View文字周围添加图标的示例,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。在Android控件View的文字周围添加图标在控件TextView文字周围放置...
    99+
    2023-06-14
  • Android:使用createNewFile()方法创建文件
    在Android中,我们可以使用File类的createNewFile()方法来创建一个新的文件。以下是一个简单的示例:```jav...
    99+
    2023-09-17
    Android
  • java获取文件的inode标识符的方法
    java获取文件的inode标识符,如果文件被删除或者重命名,inode的值会发生变更,因此可以在第一次加载File之后记录inode,后续校验inode的值来判断文件是否被删除、重...
    99+
    2024-04-02
  • Android垂直滚动控件ScrollView使用方法详解
    一、简介二、方法1)ScrollView垂直滚动控件使用方法在layout布局文件的最外层建立一个ScrollView控件在ScrollView控件中加入一个LinearLayout控件,并且把它的orientation设置为vertica...
    99+
    2023-05-30
    android 垂直滚动 scrollview
  • android侧滑菜单控件DrawerLayout使用方法详解
    drawerLayout是Support Library包中实现了侧滑菜单效果的控件,可以说drawerLayout是因为第三方控件如MenuDrawer等的出现之后,google借鉴而出现的产物。drawerLayout分为侧边菜单和主内...
    99+
    2023-05-30
  • Android中CheckBox复选框控件使用方法详解
    CheckBox复选框控件使用方法,具体内容如下一、简介类结构图二、CheckBox复选框控件使用方法这里是使用java代码在LinearLayout里面添加控件新建LinearLayout布局建立CheckBox的XML的Layout文件...
    99+
    2023-05-30
    checkbox 复选框 roi
  • Android PickerScrollView滑动选择控件使用方法详解
    本文实例为大家分享了Android PickerScrollView滑动选择控件的具体使用代码,供大家参考,具体内容如下 先看一下效果图 1.SelectBean模拟假数...
    99+
    2024-04-02
  • Android 颜色大全color.xml文件使用方法
    在Android开发中,可以使用color.xml文件来定义和管理颜色值。以下是color.xml文件的使用方法:1. 创建colo...
    99+
    2023-08-15
    Android
  • android时间选择控件之TimePickerView使用方法详解
    相信大家都有这样的一个需求,选择相应开始时间和结束时间,对数据进行筛选,下面就将使用TimePickerView实现这么一个功能。 一、先导入依赖 implementation "c...
    99+
    2024-04-02
  • Android自定义控件RatingBar调整字体大小的方法
    这篇文章主要讲解了Android自定义控件RatingBar调整字体大小的方法,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。项目需要,做一个可以调整字体大小的控件,能在滑动或点击时改变选中的位置,效果图如下:这...
    99+
    2023-05-31
    android ratingbar roi
  • Android滑动拼图验证码控件使用方法详解
    简介: 很多软件为了安全防止恶意攻击,会在登录/注册时进行人机验证,常见的人机验证方式有:谷歌点击复选框进行验证,输入验证码验证,短信验证码,语音验证,文字按顺序选择在图片上点击,滑...
    99+
    2024-04-02
  • 如何在Android中使用hover组件监控鼠标移动事件
    如何在Android中使用hover组件监控鼠标移动事件?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。Android之前对于鼠标光标事件的监控非常少,4.0之后...
    99+
    2023-05-31
    android hover roi
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作