0

I want to reference a string within another string so I only have to make changes in one place.

I don't want to handle this from Java. That is, I don't want to use %s and (getString(R.string.log_in_to_my_app), appName)

For instance, I only want to see "MyApp" in first string and a reference to it in the others:

<string name="app_name">MyApp</string>
<string name="log_in_to_my_app">Log In To MyApp</string>
<string name="login_with_my_app">Log in with MyApp</string>

So maybe something like:

<string name="app_name">MyApp</string>
<string name="log_in_to_my_app">Log In To @app_name</string>
<string name="login_with_my_app">Log in with @app_name</string>
  • 1
    Edit your question and explain what you want to do, because you only mention what you don't want to do. – forpas Feb 07 '19 at 20:02

2 Answers2

0

You can call this Strings like this:

android:text="@string/app_name"

android:text="@string/log_in_to_my_app"

android:text="@string/login_with_my_app"

0

The answer was in https://stackoverflow.com/a/39870268/6558369

<?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>