我正在尝试执行以下操作:
目前,我正在尝试使用 NativeAndroid。
不过,我可以使用 HTML 和 css 来做到这一点。
如您所见,它类似于:
- 背景为蓝色(可以是任何其他颜色,甚至是图像)的持有人
- 带有(透明??)颜色的 TextView
- 灰色背景的TextView
但是,如果我将背景设置为灰色并将文本设置为透明,则文本“消失”并且全部显示为灰色。
这是我的尝试(原生 Android):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff000000" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffcecece"
android:padding="5dp"
android:text="@string/hello_world"
android:textColor="#00ffffff" />
</RelativeLayout>
但是,它显示以下内容:
有文字,但因为是透明的,所以没有显示。
所以我的问题是:
- 我怎样才能做到这一点?
- Canvas ?跨越?我不习惯这些方法,所以我将不胜感激。
谢谢!!
编辑: 那个蓝色背景一定是动态的,它可能是一张图片!
最佳答案
您可以为此使用 Canvas:
Bitmap bmOverlay = Bitmap.createBitmap(1200, 1200, Bitmap.Config.ARGB_8888);//bMap.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawColor(Color.LTGRAY);
Paint paint = new Paint();
Paint mPaintText = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaintText.setStrokeWidth(3);
mPaintText.setStyle(Paint.Style.FILL_AND_STROKE);
mPaintText.setColor(Color.TRANSPARENT);
mPaintText.setTextSize(50f);
mPaintText.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
canvas.drawText("Your TExt", x, y, mPaintText);
关于android - 带有背景和透明文本的 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19630885/