【发布时间】:2018-01-09 07:25:18
【问题描述】:
【问题讨论】:
-
使用字体而不是创建xml。
-
@HemantParmar 我使用了外部字体,但是如何更改笔画的颜色?
-
只需更改文本颜色
标签: android text textview stroke
【问题讨论】:
标签: android text textview stroke
在 Internet 上的某个地方找到。我创建了一个自定义的textview,在onDraw方法中使用了下面的代码,它使用画布绘制来创建textview效果的Text Outline。
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
if(strokeColor!=null)
{
val textColor = textColors
val paint = this.paint
paint.style = Paint.Style.STROKE
paint.strokeJoin = strokeJoin
paint.strokeMiter = strokeMiter //10f
this.setTextColor(strokeColor)
paint.strokeWidth = strokeWidth //15f
super.onDraw(canvas)
paint.style = Paint.Style.FILL
setTextColor(textColor)
super.onDraw(canvas)
}
}
【讨论】:
onDraw方法,递归
看看这个library
示例
<com.biomorgoth.outlinetextview.StrokedTextView
android:id="@+id/your_text_view"
android:text="I am a StrokedTextView!"
android:textColor="@android:color/white"
android:textSize="25sp"
strokeAttrs:textStrokeColor="@android:color/black"
strokeAttrs:textStrokeWidth="1.7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
示例 2
<com.biomorgoth.outlinetextview.StrokedEditText
android:id="@+id/your_edit_text"
android:hint="Write here!"
android:textColor="@android:color/white"
android:textColorHint="#5fff"
android:textSize="25sp"
strokeAttrs:textStrokeColor="@android:color/black"
strokeAttrs:textStrokeWidth="1.7"
strokeAttrs:textHintStrokeColor="#5000"
strokeAttrs:textHintStrokeWidth="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
【讨论】: