Android自定义View之继承TextView绘制背景
2019/7/7 19:46:26
本文主要是介绍Android自定义View之继承TextView绘制背景,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
本文实例为大家分享了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); }
以上就是本文的全部内容,希望能给大家一个参考,也希望大家多多支持找一找教程网。
这篇关于Android自定义View之继承TextView绘制背景的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-18android.permission.read_media_video
- 2024-01-18android_getaddrinfo failed eai_nodata
- 2024-01-18androidmo
- 2024-01-15Android下三种离屏渲染技术
- 2024-01-09Android 蓝牙使用
- 2024-01-06Android对接华为AI - 文本识别
- 2023-11-15代码安全之代码混淆及加固(Android)
- 2023-11-10简述Android语音播报TTS
- 2023-11-06Android WiFi工具类
- 2023-07-22Android开发未来的出路