How to set background image inside text

Can someone tell me how to set the background image inside the text? (not a background image in the text) Is it possible to do this with the ability to draw or create a custom view. For example: https://i.ytimg.com/vi/CJHcYUuBY1M/maxresdefault.jpg

+4
source share
1 answer

I think you can use the Shader class for this purpose. Here is a sample 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 additional methods, see Docs.

+3
source

Source: https://habr.com/ru/post/1676458/


All Articles