How to make a new line or tab in XML (eclipse/android)?

前端 未结 8 975
感情败类
感情败类 2021-01-31 13:25

So, in my strings.xml I have a very long text which I want to format somehow. How can I put a tab before the first sentence of the text? Also, what is the code for new line? Tha

相关标签:
8条回答
  • 2021-01-31 13:25

    Add '\t' for tab

    <string name="tab">\u0009</string>
    
    0 讨论(0)
  • 2021-01-31 13:32

    Add \t for tab and \n for new line.

    0 讨论(0)
  • 2021-01-31 13:40
    • Include this line in your layout xmlns:tools="http://schemas.android.com/tools"
    • Now , use \n for new line and \t for space like tab.
    • Example :

      for \n : android:text="Welcome back ! \nPlease login to your account agilanbu"

      for \t : android:text="Welcome back ! \tPlease login to your account agilanbu"

    0 讨论(0)
  • 2021-01-31 13:42

    You can use \n for new line and \t for tabs. Also, extra spaces/tabs are just copied the way you write them in Strings.xml so just give a couple of spaces where ever you want them.

    A better way to reach this would probably be using padding/margin in your view xml and splitting up your long text in different strings in your string.xml

    0 讨论(0)
  • 2021-01-31 13:43

    Use \t to add tab and \n for new line, here is a simple example below.

    <string name="list_with_tab_tag">\tbanana\torange\tblueberry\tmango</string>
    <string name="sentence_with_new_line_tag">This is the first sentence\nThis is the second scentence\nThis is the third sentence</string>
    
    0 讨论(0)
  • 2021-01-31 13:50

    add this line at the top of string.xml

    <?xml version="1.0" encoding="utf-8"?>
    

    and use

    '\n'
    

    from where you want to break your line.

    ex. <string> Hello world. \n its awesome. <string>

    Output:

    Hello world.
    its awesome.
    
    0 讨论(0)
提交回复
热议问题