android textured text

后端 未结 3 2092
说谎
说谎 2021-01-06 03:08

How can I make a text with texture instead of text color or gradient(for example png file)? Something like this. I understand the logic, that I should make text color transp

3条回答
  •  既然无缘
    2021-01-06 04:00

    Sorry for posting this late but I think I will be helpful. So to make a textured text, say for example you have a file named my_layout.xml in your layout/ folder that is defined like this :

    
    
    
        
    
    
    

    and in your drawable/ folder you have a picture named texture.png, you just reference in your java code (say in the class MainActivity for instance) this way :

    public class MainActivity extends Activity
    {
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.my_layout);
            TextView welcome = (TextView) findViewById(R.id.some_text_id);
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.texture);
            Shader shader = new BitmapShader(bitmap,Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
            welcome.getPaint().setShader(shader);
    
        }
    }
    

提交回复
热议问题