Creating string resources
Every project includes a default strings file named strings.xml. In the Project tool window, find the app/res/values directory, reveal its contents, and open strings.xml.
The template has already added a few string resources for you. Remove the unused string named hello_world and add the three new strings that your layout requires.
Listing 1.3 Adding string resources (strings.xml)
<resources>
<string name="app_name">GeoQuiz</string>
<string name="hello_world">Hello world!</string><string name="question_text">Constantinople is the largest city in Turkey.</string>
<string name="true_button">True</string>
<string name="false_button">False</string>
<string name="action_settings">Settings</string></resources>
(Do not delete the action_settings string. Your project came with a menu already prepared. Deleting action_settings will cause cascading errors in other files related to the menu.) Now, whenever you refer to @string/false_button in any XMLfile in the GeoQuiz project, you will get the literal string “False” at runtime. Save strings.xml. If you had errors in activity_quiz.xml about the missing string resources, they should now be gone. (If you still have errors, check both files for typos.) Although the default strings file is named strings.xml, you can name a strings file anything you want. You can also have multiple strings files in a project. As long as the file is located in res/values/, has a resources root element, and contains child string elements, your strings will be found and used appropriately.
Every project includes a default strings file named strings.xml. In the Project tool window, find the app/res/values directory, reveal its contents, and open strings.xml.
The template has already added a few string resources for you. Remove the unused string named hello_world and add the three new strings that your layout requires.
Listing 1.3 Adding string resources (strings.xml)
<resources>
<string name="app_name">GeoQuiz</string>
<string name="true_button">True</string>
<string name="false_button">False</string>
<string name="action_settings">Settings</string></resources>
(Do not delete the action_settings string. Your project came with a menu already prepared. Deleting action_settings will cause cascading errors in other files related to the menu.) Now, whenever you refer to @string/false_button in any XMLfile in the GeoQuiz project, you will get the literal string “False” at runtime. Save strings.xml. If you had errors in activity_quiz.xml about the missing string resources, they should now be gone. (If you still have errors, check both files for typos.) Although the default strings file is named strings.xml, you can name a strings file anything you want. You can also have multiple strings files in a project. As long as the file is located in res/values/, has a resources root element, and contains child string elements, your strings will be found and used appropriately.






0 nhận xét:
Đăng nhận xét