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);
}
以上就是本文的全部内容,希望能给大家一个参考,也希望大家多多支持phpstudy。相关阅读:
jquery+php实现搜索框自动提示
JavaScript事件委托的技术原理探讨示例
探讨SQL利用INFORMATION_SCHEMA系统视图如何获取表的主外键信息
深入PHP异步执行的详解
jQuery使用之设置元素样式用法实例
C#通过经纬度计算2个点之间距离的实现代码
Win10 10532应用商店更新有哪些变化? 新旧版本对比图赏
CSS的writing-mode文字排版属性使用教程
win7系统怎么设置任务栏透明度 win7任务栏透明度设置图文教程
在CentOS系统上安装Jetty服务器的教程
Mac怎么改finder图标 苹果Mac修改finder字体大小图文教程
对行内元素和块级元素的一些认识
JSP中 Session和作用域的使用
PHP加密解密类实例分析