Android – how to set a background image in text
•
Android
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
二维码