我想做的事? (蓝色将变为白色)
我做了什么?
我找到了一个扩展TextVIEw的类,它能够非常接近我想要的文本视图.问题是我无法将笔触颜色更改为任何颜色,它总是绘制为黑色.如何将边框颜色设置为白色?
我的输出是什么:
我的代码在哪里?
@H_419_13@public class TypeFaceTextVIEw extends TextVIEw {private static Paint getWhiteborderPaint(){ Paint p = new Paint(color.WHITE); return p;}private static final Paint BLACK_border_PAINT = getWhiteborderPaint();static { BLACK_border_PAINT.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));}@OverrIDepublic voID setText(CharSequence text,BufferType type) { super.setText(String.format(text.toString()),type);}private static final int border_WIDTH = 1;private Typeface typeface;public TypeFaceTextVIEw(Context context) { super(context);}public TypeFaceTextVIEw(Context context,AttributeSet attrs) { super(context,attrs); setDrawingCacheEnabled(false); setTypeface(attrs);}private voID setTypeface(AttributeSet attrs) { final String typefacefilename = attrs.getAttributeValue(null,"typeface"); if (typefacefilename != null) { typeface = Typeface.createFromAsset(getContext().getAssets(),typefacefilename); } setTypeface(typeface);}public TypeFaceTextVIEw(Context context,AttributeSet attrs,int defStyle) { super(context,attrs,defStyle); setTypeface(attrs);}@OverrIDepublic voID draw(Canvas aCanvas) { aCanvas.saveLayer(null,BLACK_border_PAINT,Canvas.HAS_Alpha_LAYER_SAVE_FLAG | Canvas.FulL_color_LAYER_SAVE_FLAG | Canvas.MATRIX_SAVE_FLAG); drawBackground(aCanvas,-border_WIDTH,-border_WIDTH); drawBackground(aCanvas,border_WIDTH + border_WIDTH,0); drawBackground(aCanvas,border_WIDTH + border_WIDTH); drawBackground(aCanvas,-border_WIDTH - border_WIDTH,0); aCanvas.restore(); super.draw(aCanvas);}private voID drawBackground(Canvas aCanvas,int aDX,int aDY) { aCanvas.translate(aDX,aDY); super.draw(aCanvas);}}最佳答案1)创建textvIEw对象扩展TextVIEw
@H_419_13@public class YourTextVIEw extends TextVIEw { .........
2)在绘制方法上执行此 *** 作
@H_419_13@@OverrIDepublic voID draw(Canvas canvas) { for (int i = 0; i < 5; i++) { super.draw(canvas); }}
3)设置textvIEw的xml端如下
@H_419_13@androID:shadowcolor="@color/white"androID:shadowRadius="5"总结
以上是内存溢出为你收集整理的android – 如何勾勒出TextView?全部内容,希望文章能够帮你解决android – 如何勾勒出TextView?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)