源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android自定义View之继承TextView绘制背景

  • 时间:2021-05-10 05:56 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android自定义View之继承TextView绘制背景
本文实例为大家分享了TextView绘制背景的方法,供大家参考,具体内容如下 [b]效果:[/b] [img]http://files.jb51.net/file_images/article/201605/2016052510153929.png[/img] [b]实现流程:[/b] [img]http://files.jb51.net/file_images/article/201605/2016052510153930.png[/img] [b]1.初始化:对画笔进行设置[/b]
mPaintIn = new Paint();
mPaintIn.setAntiAlias(true);
mPaintIn.setDither(true);
mPaintIn.setStyle(Paint.Style.FILL);    

mPaintIn.setColor(getResources().getColor(R.color.colorPrimary));

mPaintOut = new Paint();
mPaintOut.setAntiAlias(true);
mPaintOut.setDither(true);
mPaintOut.setStyle(Paint.Style.FILL);   

mPaintOut.setColor(getResources().getColor(R.color.colorAccent));
[b]2.绘制外框,内框,文字[/b] [b]获取组件宽高[/b]
int width = getMeasureWidth();
int height = getMeasureHeight();

[b]绘制[/b]
@Override
  protected void onDraw(Canvas canvas) {
    //绘制背景,在绘制文字之前绘制
    canvas.drawRect(new Rect(0, 0, getMeasuredWidth(), getMeasuredHeight()), mPaintIn);
    canvas.drawRect(new Rect(10, 10, getMeasuredWidth()-10, getMeasuredHeight()-10), mPaintOut);

    super.onDraw(canvas);
  }


以上就是本文的全部内容,希望能给大家一个参考,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部