I want to display a string with leading whitespace in a Textview. But what I can see is that the android Textview is trimming all leading/trailing whitespace. Is there a way to turn this behavior off?
Asked
Active
Viewed 6,696 times
8
-
I think this should be very useful to you http://codereview.stackexchange.com/questions/3099/android-remove-useless-whitespace-from-styled-string – Ramkumar Aug 10 '12 at 11:42
-
That's unfortunately right. I just verified with some other view and there it works as expected. Sorry... – tmanthey Aug 10 '12 at 17:15
1 Answers
13
Old question but if you are not satisfied with "It Does Not trim itself." answer from comments this might help you.
If you are using resource strings with leading or trailing spaces, this is your issue: How to keep the spaces at the end and/or at the beginning of a String?
TextView indeed doesn't trim whitespaces but whatever reads strings from XML does. Use \u0020
instead of spaces.

Community
- 1
- 1

Emperor Orionii
- 703
- 10
- 22