Formatting of Android strings and string resources

Source: Internet
Author: User

Why write this essay? In the course of recent projects, there are a lot of pages in the process of displaying text, some are fixed text, some are dynamically acquired, and the format is various. At first, take a stupid approach, split it into text controls, and then use different styles for different controls. This is done efficiently.

is very low, and the alignment between the text is a big problem, and then go to the Internet for help, find some information about the Android string and string resource formatting articles, here to do a summary.

One, string formatting

The Java String class gives us two overloaded methods for formatting strings that can be passed into a fixed string by means of a placeholder. They were:

Format (string format, Object ... args) a new string that uses the local locale to develop a string format and parameters to generate a new formatted string.

Format (locale locale, string format, Object ... args) uses the specified locale to develop string formatting and parameters to generate a formatted string.

For example:

String placeholder%s:system.out.println ("hi,%s", "Wang Li") output Hi, Wang Li

Decimal Shaping Placeholder%d:system.out.println ("I am%d years old", 20) output I am 20 years old this year

Floating-point placeholder%f:system.out.println ("Litchi Price is%f yuan", 3.5) output Litchi Price is 3.5 yuan

There are other formatting methods, such as character type, shaping, date format, and so on.

Not to be continued ...

Formatting of Android strings and string resources

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.