Skip to content Skip to sidebar Skip to footer

How To Set Background Of A Textview Dynamically From Xml File

I have an xml file like below which I will use to set background for Textview: row.xml setBackgroundDrawable(Drawable d).

This will set the background using the given Drawable. So it would look something like this:

TextViewt1= (TextView) findViewById(R.id.rowtext3);
t1.setBackgroundDrawable(row);

Solution 2:

If I understand you correctly, findViewById(int id) from the Activity class is what you're looking for. When you have retrieved the view, you can set the background using setBackgroundResource(int id). The parameter id can be found in your generated R-file, e.g. findViewById(R.drawable.row).

Post a Comment for "How To Set Background Of A Textview Dynamically From Xml File"