Default apidemo Font Style

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.