电话
400 9058 355
本文实例为大家分享了TextView绘制背景的方法,供大家参考,具体内容如下

效果:
实现流程:
1.初始化:对画笔进行设置
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));
2.绘制外框,内框,文字
获取组件宽高
int width = getMeasureWidth(); int height = getMeasureHeight();
绘制
@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);
}
以上就是本文的全部内容,希望能给大家一个参考,也希望大家多多支持。
邮箱:8955556@qq.com
Q Q:8955556
这篇文章主要为大家详细介绍了Android自定义控件实现底部...
这篇文章主要介绍了Android中Toolbar随着Scro...
本文主要介绍了Java图表类库的相关知识。具有很好的参考价值...
本文主要介绍了GIt的基本操作。具有很好的参考价值,下面跟着...
共享内存是在两个正在运行的进程之间共享和传递数据的一种非常有...
这篇文章主要为大家详细介绍了Android自定义相机实现定时...
这篇文章主要介绍了CentOS6.5 上部署 MySQL5....
这篇文章主要介绍了Vue结合原生js实现自定义组件自动生成示...
最近在学习python网络编程这一块,在写简单的socket...
这篇文章主要介绍了微信小程序 数据交互与渲染实例详解的相关资...