Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we create new_strings.xml with strings.xml in values folder for sting strings (Android)?

Tags:

string

android

I have two xml files in values folder for strings:

  1. new_strings.xml
  2. strings.xml

From strings.xml I can access string as follows:

String str = getString(R.string.app_name);

How can I directly access from new_strings.xml?

like image 757
user1482641 Avatar asked Aug 20 '12 12:08

user1482641


1 Answers

By the same way you're accessing the values in strings.xml file.

Example :

strings.xml :

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name_1">First app name</string>

</resources>

new_strings.xml :

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name_2">Second app_name</string>

</resources>

In your java code you can do :

R.string.app_name_1

R.string.app_name_2

and you can access both values which are in two different xml files.

As the doc said: file location:

res/values/filename.xml

The filename is arbitrary. The <string> element's name will be used as the resource ID.

compiled resource datatype: Resource pointer to a String.

like image 63
Alexis C. Avatar answered Sep 18 '22 00:09

Alexis C.