android 文字描边
来源:互联网 发布:拆弹部队知乎 编辑:程序博客网 时间:2024/05/21 14:06
package com.weipeng.textviewcolor;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.text.TextPaint;import android.util.AttributeSet;import android.view.ViewGroup;import android.widget.TextView;/** * Created by Administrator on 2016/3/31. *//* * StrokeTextView的目标是给文字描边 * 实现方法是两个TextView叠加,只有描边的TextView为底,实体TextView叠加在上面 * 看上去文字就有个不同颜色的边框了 */public class StrokeTextView extends TextView { private TextView borderText = null;///用于描边的TextView public StrokeTextView(Context context) { super(context); borderText = new TextView(context); init(); } public StrokeTextView(Context context, AttributeSet attrs) { super(context, attrs); borderText = new TextView(context,attrs); init(); } public StrokeTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); borderText = new TextView(context,attrs,defStyle); init(); } public void init(){ TextPaint tp1 = borderText.getPaint(); tp1.setStrokeWidth(10); //设置描边宽度 tp1.setStyle(Paint.Style.STROKE); //对文字只描边 borderText.setTextColor(Color.RED); //设置描边颜色 borderText.setGravity(getGravity()); } @Override public void setLayoutParams (ViewGroup.LayoutParams params){ super.setLayoutParams(params); borderText.setLayoutParams(params); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { CharSequence tt = borderText.getText(); //两个TextView上的文字必须一致 if(tt== null || !tt.equals(this.getText())){ borderText.setText(getText()); this.postInvalidate(); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); borderText.measure(widthMeasureSpec, heightMeasureSpec); } protected void onLayout (boolean changed, int left, int top, int right, int bottom){ super.onLayout(changed, left, top, right, bottom); borderText.layout(left, top, right, bottom); } @Override protected void onDraw(Canvas canvas) { borderText.draw(canvas); super.onDraw(canvas); }}
0 0
- Android文字描边
- android 文字描边
- Android开发:文字描边
- android文字描边效果
- Android之文字描边
- 实现android文字描边功能
- 图片,文字描边。
- 文字描边方法
- CCLableTTF 文字描边
- 文字描边
- TextView 文字描边
- Flex 文字描边效果
- GDI+中文字描边
- ios UILabel文字描边
- cocos2d-x 文字描边
- cocos2d-x 文字描边
- CCLabelTTF制造文字描边
- Flash原生文字描边
- 服务器403错误的问题
- 装修注意事项
- 动态树(Link-Cut-Tree)结构与实现简讲
- sdut1252 进制转换
- 用Eclipse新建一个web项目没有自动生成web.xml
- android 文字描边
- 我的第一篇破壳
- 在X-window下安装gcc
- URL的深入学习总结
- C++第二次实验上机报告(计算标准体重)
- 浅谈linux和windows的线程机制的区别
- 1007. Maximum Subsequence Sum (25)
- POJ 2513 Colored Sticks
- 《剑指Offer》学习笔记——面试