Other usage of strings. xml in Android

Source: Internet
Author: User

Other usage of strings. xml in Android
Usage 1: normal string


  
          
   
    text_string
   
  
Usage 2: string Array

  
      
           
    
     text_string
        
   
  

Java code:

Resources res = getResources();String[] planets = res.getStringArray(R.array.planets_array);
Usage 3: Plurals

  
      
           
    
     One song found.
            
    
     %d songs found.
        
   
  

Java code:

int count = getNumberOfsongsAvailable();Resources res = getResources();String songsFound = res.getQuantityString(R.plurals.numberOfSongsAvailable, count);
Usage 4: Formatting and Styling Formatting, placeholder, etc.

1. format the string


  
   
Hello, % 1 $ s! You have % 2 $ d new messages.
  // Java code Resources res = getResources (); String text = String. format (res. getString (R. string. welcome_messages), username, mailCount );

2. html


  
      
   
    Welcome to 
    Android!
   
  

3. Combination of the above two methods


    
   
    Hello, %1$s! You have <b>%2$d new messages</b>.
   
  Resources res = getResources();String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);CharSequence styledText = Html.fromHtml(text);

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.