Android – how to set a background image in text

Who can tell me how to set the background image in the text? (not a textview background picture) can I use drawable or create a custom view? Like this: https://i.ytimg.com/vi/CJHcYUuBY1M/maxresdefault.jpg

resolvent:

I think you can use the shader class to achieve this. Here is the example code:

    Bitmap bitmapObj  = BitmapFactory.decodeResource(getResources(),R.drawable.your_image);
    Shader shaderObj = new BitmapShader(bitmapObj,Shader.TileMode.REPEAT,Shader.TileMode.REPEAT);
    textViewObj.getPaint().setShader(shaderObj);
    textViewObj.setText("hello");

For more methods, see docs

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>