如何在我的textView的文字周围制作黑线?例如上述图像围绕文字的黑线
Q
围绕文字的黑线
2
A
回答
5
上扩展的TextView类。然后在onDraw中,首先使用黑色绘制文本,然后再次绘制,稍微小一些,并使用白色。为了获得额外的“正确性”,请将自定义属性添加到XML以设置“线条”颜色。
public class myTextView extends TextView{
public myTextView (Context context) {
this(context, null);
}
public myTextView (Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public myTextView (Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// do extra initialisation and get attributes here
}
@Override
protected void onDraw(Canvas canvas) {
// draw first in black
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(20); // text size
paint.setStyle(Paint.Style.STROKE);
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText("My text", 50, 50, paint);
// draw again in white, slightly smaller
paint.setColor(Color.WHITE);
paint.setTextSize(18); // text size
canvas.drawText("My text", 50, 50, paint);
}
}
的代码是不完整的,因为它的硬编码的颜色,大小和位置,但我希望这是足以让你一起工作。您可以通过构造函数中的attrs从XML获取文本大小和文本颜色,并将行颜色和宽度添加为自定义属性(在此处搜索或Google)。
+0
非常感谢你 –
+0
不客气。 – Simon
4
0
描述一下添加到您的xml文件的字体:
android:shadowColor="#000000"
android:shadowDx="1.5"
android:shadowDy="1.3"
android:shadowRadius="1.6"
android:text="YOUR TEXT"
android:textColor="@color/white"
相关问题
- 1. 黑客围绕IE
- 2. 围绕文字环绕HTML
- 3. 围绕固定分隔线围绕文本
- 4. iPhone:围绕图像环绕文字
- 5. 围绕图片环绕文字IE
- 6. 围绕图像环绕文字
- 7. Flex 4 - 围绕图像环绕文字
- 8. 围绕着浮动环绕文字
- 9. 围绕图像环绕文字
- 10. 围绕文字环绕一个div
- 11. 围绕EditFields的边界 - 黑莓
- 12. 围绕左下角div围绕文本?
- 13. 围绕相对位置div div围绕文字
- 14. 围绕两行文字旁边的一条线,引导
- 15. 围绕线条的圆圈 - 崇高文字3
- 16. 文字环绕图像周围的
- 17. 围绕图像错误的Android文字
- 18. 围绕编辑文字的边框
- 19. 用Joomla围绕Seblod中的元素围绕文章文本
- 20. iphone石英画线围绕线条
- 21. 围绕一个DIV中的所有数字围绕SPAN
- 22. 围绕文字换行不换行
- 23. 环绕文字图像周围(响应)
- 24. PHPWord - 在表格周围环绕文字
- 25. 围绕广场图像居中文字
- 26. 用css围绕圆圈文字
- 27. 在DIV上和周围环绕文字
- 28. AS3围绕中心旋转文字?
- 29. 围绕span-chrome问题换行文字
- 30. 用文字围绕双引号图片
我不明白,MS油漆? PhotoShop的?瘸子? –
尝试在它后面放置一个黑色阴影:http://stackoverflow.com/questions/3182393/android-textview-outline-text – Ahmad
@DannyHong我认为Max想勾勒出他的文字。 – Ahmad