Summary of the use of string. XML in Android

Source: Internet
Author: User
Tags italic font

<B> </B> bold font

<I> </I> italic font

<U> </u> underline the font.

\ N line feed

\ U0020 indicates space

\ U2026 indicates the ellipsis

Use & lt; B> and & lt; B> to print the text like <B> </B>. "& lt;" indicates the meaning of "<;

Use textview. settext (html. fromhtml ("Hello <B> world </B>, <font size = \" 3 \ "color = \" Red \ "> analysisxmlactivty! </Font> "); Set effects similar to those in HTML.

If you need to format your string using string. Format (string, object...), you can put the format parameter in your string. See the following example:

<String name = "welcome_messages"> hello, % 1 $ s! You have % 2 $ d new messages. </string>

In this example, the formatted string has two parameters, % 1 $ S is a string % 2 $ D is a floating point number, you canProgramFormat the string according to the parameters in the following method:

Resources res = getresources ();

String text = string. Format (res. getstring (R. String. welcome_messages), username, mailcount );

As mentioned in the example, I need to replace % s with % 1 $ S. After the modification, the program is compiled and started successfully.

Question added: how to use the "%" in <string> </string>

There are two ways to choose from

1. Use % to indicate 1%, which is the same as the conversion symbol \.

2. if your string does not need to be formatted, you can add an attribute on your <string Tag: formatted = "false" for example, <string name = "test" formatted = "false"> % test % </string>.

Related Article

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.