1: XML
Android: textstyle = "normal"
Android: textstyle = "bold"
Android: textstyle = "italic"
Normal, bold, italic
2: String. xml configuration
Plain, <B> bold </B>, <I> italic </I>, <B> <I> bold-italic </I>
3:
Get the string's use of gettext () without losing the text font style information,
Getstring () will lose the western information.
Another way is that this. getresources. gettext () will not lose text style information.
// See Res/Any/layout/resources. XML for this view layout definition.
Setcontentview (R. layout. Resources );
Textview TV;
Charsequence Cs;
String STR;
// ====== Using the context. getstring () convenience method ============
// Using the getstring () conevenience method, retrieve a string
// Resource that hapepns to have style information. Note the use
// Charsequence instead of string so we don't lose the style info.
Cs = gettext (R. String. styled_text );
TV = (textview) findviewbyid (R. Id. styled_text );
TV. settext (CS );
// Use the same resource, but convert it to a string, which causes it
// To lose the style information.
STR = getstring (R. String. styled_text );
TV = (textview) findviewbyid (R. Id. plain_text );
TV. settext (STR );
// ======= Using the resources object =================================== =====
// You might need to do this if your code is not in an activity.
// For example view has a protected mcontext field you can use.
// In this case it's just 'This' since activity is a context.
Context context = this;
// Get the resources object from our context
Resources res = context. getresources ();
// Get the string resource, like above.
Cs = res. gettext (R. String. styled_text );
TV = (textview) findviewbyid (R. Id. RES1 );
TV. settext (CS );
// Note that the resources class has methods like getcolor (),
// Getdimen (), getdrawable () Because themes are stored in resources.
// You can use them, but you might want to take a look at the view
// Examples to see how to make m widgets.