0

I had a scenario where I need to have spaces for android:text attribute value.
android:text="Input type" ---> I need output with 5 spaces between "Input" and "type" Strings
How can I achieve the above result.

Thanks in Advance

2
  • your problem is not properly clear.. do you want 5 spaces after first letter end via programmatically ? Commented Jun 17, 2014 at 12:40
  • The String "Input Type" should have 5 spaces between them but I see only one white space considered though I give 5 spaces between "Input" and "Type" Commented Jun 17, 2014 at 12:46

4 Answers 4

2
<TextView
    android:id="@+id/xxx"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="@string/empty_spaces" />

in strings.

<string name="empty_spaces">Input\t\t type</string>
Sign up to request clarification or add additional context in comments.

2 Comments

but the problem it works fine in one and does n't work fine in another device. How can we handle device density in this case
this will work in all devices, if you want to do it with different devices you can add this in values-hdpi\strings.xml and also in values-mdpi/strings.xml file
1

You can replace spaces by \u0020

<TextView android:text="Input\u0020\u0020\u0020\u0020\u0020types" />

Comments

1

It's better to use string ressources.

Put all your string value in a file on res/values/strings.xml.

If you want to add space you can do it by surround your text by double quotes.

You can see an example in the documentation : http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling

Comments

1

Add this &#160; with your strings in xml file

<string name="stringsample">Sample:&#160;</string>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.