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