2

This isn't exactly a programming question, but it's a question specifically about Android Studio.

I am working on a song lyrics app, and I am I have been asked to add the chords to songs, which is what I am doing. So I have the songs formatted in the following way; I have chords on 1 line, and lyrics on the next. In order to have the chords and lyrics show up properly, I need the chord line to be the exact same length as the lyrics line. This usually includes adding a few spaces at the end of the chord line, to match the length. But I noticed that Android Studio automatically erases all the necessary spaces at the end.

Any suggestions on what I could do??

Eddie
  • 31
  • 8

2 Answers2

2

There's a way to add spaces in your strings.xml file with double quotes. Please refer this doc

<string name="my_space_string">"    This will work perfectly   "</string>

or just use the UTF Code to add spaces.

<string name="my_space_string">\u0020\u0020This will work perfectly.\u0020\u0020</string>

I hope this helps you..

Vinoth Vino
  • 9,166
  • 3
  • 66
  • 70
  • I almost have no experience with `Strings.xml`, so I dont know how to add a string from `Strings.xml` directly to the `.txt` file – Eddie Mar 04 '17 at 05:19
  • You can access strings in the strings.xml file from your java code directly. See this link http://stackoverflow.com/a/2184151/4608334 and please refer the official document too https://developer.android.com/guide/topics/resources/string-resource.html – Vinoth Vino Mar 04 '17 at 05:32
  • Solved your problem ? If my answer helps you then accept it. @Eddie – Vinoth Vino Mar 05 '17 at 01:17
1

You may need to replace spaces with the unicode space characters \u0020.

For example, <string name="name">Text\u0020</string>.

Or as Vinoth has noted, just surround the text with quotation marks and add your spaces.

BST
  • 11
  • 4
  • That just displays `\u0020` Literally – Eddie Mar 04 '17 at 03:16
  • Instead of adding them to the text file, can you store each chord line as a separate string in the strings.xml file, and add these characters there? – BST Mar 04 '17 at 03:38