Can I use a String Resource in a String Resource in string.xml?

As the title says, my problem is that I don't know If/How I can use a String Resource in a String Resource in string.xml.

<string name="projectname">Include Test</string>
<string name="about">@string/projectname is to test if you can use a String Resource in a String Resource</string>

My question is if anyone knows if I can write

<string name="identifier">@string/other_identifier</string>

because Eclispe says

error: Error: No resource found that matches the given name (at 'other_identifier' with value '@string/other_identifier eingeben...').

You are better off constructing these Strings at runtime. Combine different String resources together with the help of String.format.

Further details: http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling

You can modify it from resources tab as well, just select the string resource you want to modify and change its attributes, Name and Value at the right side. How to add a new String Resource.? Open Strings.xml from project explorer and select the Resources tab in it if already not selected, and click Add button. Strings.xml – Resources tab


No, I don't think that is possible.

Yes you can :) Not natively though, but you can use this small library that allows you to resolve these placeholders at buildtime, so you won't have to add any Java/Kotlin code to make it work.


Edit: Actually this solution, using custom ENTITY entries is much nicer.


The following should work out of the box:

<string name="identifier">@string/other_identifier</string>

I just tried it with API Level 8 and it works fine. See also https://stackoverflow.com/a/6378421/786434

To be able to cross-reference strings within other words, you can create yourself a small helper method:

private static Pattern pattern = Pattern.compile("@string/(\\S+)");

public static String getString(Resources res, int stringID) {
String s = res.getString(stringID);

Matcher matcher = pattern.matcher(s);
while (matcher.find()) {
    try {
    final Field f = R.string.class.getDeclaredField(matcher.group(1));
    final int id = f.getInt(null);
    final String replace = res.getString(id);
    s = s.replaceAll(matcher.group(), replace);

    } catch (SecurityException ignore) {
    } catch (NoSuchFieldException ignore) {
    } catch (IllegalArgumentException ignore) {
    } catch (IllegalAccessException ignore) {
    }
}

return s;
}

We’re using this pattern for string resource names for quite a long time now and for different kinds of Android projects. Even before we started to automate the extraction process.


A nice way to insert a frequently used string (e.g. app name) in xml without using Java code here:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE resources [
<!ENTITY appname "MyAppName">
<!ENTITY author "MrGreen">
]>

<resources>
    <string name="app_name">&appname;</string>
    <string name="description">The &appname; app was created by &author;</string>
</resources>

STRINGTABLE resource. 05/31/2018; 2 minutes to read; In this article. Defines one or more string resources for an application. String resources are simply null-terminated Unicode or ASCII strings that can be loaded when needed from the executable file, using the LoadString function.


Yes you can :) Not natively though, but you can use this small library that allows you to resolve these placeholders at buildtime, so you won't have to add any Java/Kotlin code to make it work.

Based on your example, you'd have to set up your strings like this:

<string name="projectname">Include Test</string>
<string name="template_about">${projectname} is to test if you can use a String Resource in a String Resource</string>

And then the plugin will take care of creating the following:

<string name="about">Include Test is to test if you can use a String Resource in a String Resource</string>

More info here: https://github.com/LikeTheSalad/android-string-reference

Disclaimer: I'm the author of that library.

Definition of String in XML. XML Schema defines in a way what an XML document contains, therefore, XSD defines the string so, it can be defined as a value that contains character strings also has Unicode character given by XML and represented using the type xs: string, while this type has a white space character and maintained by the processor as data types, can pick characters, line feeds as


Refer to a string resource identifier from XAML. You use an x:Uid directive to associate a control or other element in your markup with a string resource identifier. <TextBlock x:Uid="Greeting"/> At run-time, \Strings\en-US\Resources.resw is loaded (since right now that's the only Resources File in the project).


But when I change the Locale and Configuration (pretty much what I have to do when I want to change a language in Android) it doesn't work. It either shows me the id of the string resource, throws an exception if I try to get a translation in my code or it shows the default if I have the default translations in there.


Ukulele sheet music for beginner groups offering simple melody and harmony parts using only the open strings! Resources included: Overview of parts and some possible teaching applications. Sheet music for different sections including ukulele, Bass Ukulele, and Percussion ( I use the Djembe but any percussion will work!).