0

Is there a way to set the value of an xml string tag value to include that of another string tag value. The idea is like this:

<string name="tag1">"this is"</string>
<string name="tag2"><tag1 + " what I mean"</string>

Is this possible and if so how do I do it?

azizbekian
  • 60,783
  • 13
  • 169
  • 249
Ryan
  • 727
  • 2
  • 14
  • 31

2 Answers2

0

Is this possible and if so how do I do it?

Arithmetic, concatenation operations are not possible in android resource files.

azizbekian
  • 60,783
  • 13
  • 169
  • 249
0

You can concatenate strings without writing any Java/Kotlin code, only XML by using this small library I created which does so at buildtime: https://github.com/LikeTheSalad/android-stem

Usage

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

<string name="tag1">this is</string>
<string name="tag2">${tag1} what I mean</string>

And then after building your project, you'll get:

<!-- Auto generated during compilation -->
<string name="tag2">this is what I mean</string>
César Muñoz
  • 535
  • 1
  • 6
  • 10