How Android studio easily organizes strings into String.xml

Source: Internet
Author: User

1, the string written in the layout file, organized into String.xml

1, such as the following layout files, generally write the layout of the file when the string is directly written into the inside, and then sorted into the String.xml:

< TextView         Android:layout_width = "Wrap_content"         android:layout_height= "Wrap_content"        android:text= "Test Alt+enter"          android:maxlines= "1"        android:textsize= "36SP"  />


At this point, you will be prompted to organize the string into String.xml, in order to facilitate the i18n of international processing, as shown in:

2, then check the string "Test Alt+enter", while holding down alt+enter, you can see the popup selected dialog, select the "Extract string resource", as shown in:

Select "Extract string Resource", which appears as shown in the dialog box

You can then modify the string's key value in String.xml, as shown in:

After the modification, click "OK" button, will automatically modify the code as shown below:

   < TextView         Android:layout_width = "Wrap_content"         android:layout_height= "Wrap_content"        android:text= "@string/test_alt_ Enter "        android:maxlines=" 1 "        android:textsize=" 36SP "  />

Also, the corresponding code is automatically generated in the String.xml file, as shown in:

<name= "Test_alt_enter"> Test alt+enter</string >

2, the string written in the Java file, organized into String.xml

And the string that is written in the layout file, the way it is organized into String.xml is the same, and is also handled by using ALT + ENTER shortcut keys, as shown in:

Tvnavchanneltitle.settext ("Test alt+enter in Java files");

Use the ALT + ENTER shortcut key, and then pop up the following dialog box

Select the "Extract string resource", and then pop the dialog box as shown, and then modify the string's key value in String.xml

Click on the "OK" button and the code will be automatically modified as follows:

Tvnavchanneltitle.settext (R.string.test_alt_enter_java);

Also, the corresponding code is automatically generated in the String.xml file, as shown in:

<string name= "Test_alt_enter_java" > Test alt+enter</string> in Java files

Summary: Press Alt+enter for code hint changes where you need to defragment a string

Original source: http://blog.csdn.net/ouyang_peng/article/details/52280656

How Android studio easily organizes strings into String.xml

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.