Android Studio string hello_world is not present in string.xml

I am new to Android app development, trying to follow an intro-book on this subject. After creating an empty project, I will be asked to open the string.xml file, which should contain the <string name="hello_world">Hello World!</string> element to edit the default text of the TextView object. However, the file does not contain this element. It contains only:

enter image description here

In addition, only the activity_main.xml layout file is displayed in the book, while I see activity_main.xml and content_main.xml files.

Perhaps this is a version issue? My Android SDK installation is on Windows 10 with the latest API 23, whereas I think the book was published before API 23 was released.

+5
source share
1 answer

The default project template has probably changed since the writing of the book.

Try creating a new project, and when asked, select "Empty action" instead of "Empty action." This should include only activity_main.xml

This does not include the hello_world line in the resources, so just add it yourself by adding a line with

 <string name="hello_world">Hello World!</string> 

in strings.xml

In addition, they decided to break the agreement that they were going to use for the default template. There is a TextView activity_main.xml layout, but it uses a string chain, not a string resource.

If you change the text attribute of this TextView to: @string/hello_world , you can reflect the desired behavior that the book requests.

Here is a page right from the official Android docs on String resources. This may help you better understand: https://developer.android.com/guide/topics/resources/string-resource.html

+8
source

Source: https://habr.com/ru/post/1239601/


All Articles