Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio string hello_world not present in string.xml file

I'm new to Android app development, trying to follow an intro book on the subject. After creating a blank project, I'm instructed to open the string.xml file, which is supposed to contained the element <string name="hello_world">Hello World!</string> in order to edit the default text of the TextView object. However, the file doesn't contain this element. It only contains:

enter image description here

Also, the book only shows an activity_main.xml layout file, whereas I'm seeing both an activity_main.xml and a content_main.xml file.

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

like image 708
yroc Avatar asked Dec 31 '15 22:12

yroc


1 Answers

The default project template has probably changed since the book was written.

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

This doesn't include the hello_world string in the resources however, so just add it yourself by adding a line with

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

to the strings.xml

Moreover, they decided to break the convention they had been going with for the default template. There is a TextView in the activity_main.xml layout, but it uses a hardcoded string, rather than a string resource.

If you modify the text attribute of this TextView to: @string/hello_world, you should be able to mirror the desired behavior that the book is asking for.

Here's a page straight out from the official Android docs on String resources. It may help you understand it better: https://developer.android.com/guide/topics/resources/string-resource.html

like image 100
Andrew Brooke Avatar answered Nov 16 '22 04:11

Andrew Brooke