EF's Blog

Android Tutorial : Set Style on TextView / Other Object on Runtime (via Code)

Posted on: May 22, 2012

I do not believe you can set the style programatically. To get around this you can create a template layout xml file with the style assigned, for example in res/layout create tvtemplate.xml as with the following content:

<?xml version=”1.0″ encoding=”utf-8″?>

<TextView xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”This is a template”
style=”@style/my_style” />

then inflate this to instantiate your new TextView:

TextView myText = (TextView)getLayoutInflater().inflate(R.layout.tvtemplate, null);

Hope this helps.

2 Responses to "Android Tutorial : Set Style on TextView / Other Object on Runtime (via Code)"

it rly hlpd me
thnx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

EF’s Blog

I'm just ordinary people who lived in an extra-ordinary world.

EF's Blog Stats

  • 126,562 hits
May 2012
M T W T F S S
« Apr   Jul »
 123456
78910111213
14151617181920
21222324252627
28293031  

Archives

%d bloggers like this: