作者:你有小号我就不能有吗_477 | 来源:互联网 | 2023-02-03 14:26
1> andras..:
这个答案让我走上了正确的道路:https:
//stackoverflow.com/a/28625166/4420543
因此,解决方案是创建自定义Textview并覆盖onDraw方法:
@Override
protected void onDraw(Canvas canvas) {
final Paint paint = getPaint();
final int color = paint.getColor();
// Draw what you have to in transparent
// This has to be drawn, otherwise getting values from layout throws exceptions
setTextColor(Color.TRANSPARENT);
super.onDraw(canvas);
// setTextColor invalidates the view and causes an endless cycle
paint.setColor(color);
System.out.println("Drawing text info:");
Layout layout = getLayout();
String text = getText().toString();
for (int i = 0; i