Tuesday, May 3, 2011

How to dynamically change TextView font color in Android

The following is an easy way to change the font color dynamically in activities.

Activity Code:

String msg = "Hello World!";
TextView tv = (TextView) findViewById(R.id.tv);
txt.setText(Html.fromHtml("<font color='green'>" + msg + "</font>"));

XML layout Code:

<TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content"/>

No comments:

Post a Comment