Android自定义View绘制背景 Android自定义View之继承TextView绘制背景
Brioal 人气:0想了解Android自定义View之继承TextView绘制背景的相关内容吗,Brioal在本文为您仔细讲解Android自定义View绘制背景的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Android,自定义,View,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); }
以上就是本文的全部内容,希望能给大家一个参考,也希望大家多多支持。
加载全部内容