Using tabulator / tabspace in a TextView

前端 未结 3 402
南笙
南笙 2020-12-29 05:42

I wish to use some tabspace in a line where I call setText

if(id==R.id.radioButton1){
            title.setText(numbertext.getText()+\" Grams\");


        
相关标签:
3条回答
  • 2020-12-29 06:06

    If "\t" doesn't work and \u0009 (Unicode for a tab) only shows 1 space:

    In values/strings.xml add

    <string name="tab">\u0009\u0009\u0009\u0009</string>
    

    Then in your Java file add

    textView.setText("text" + getString(R.string.tab) + "moretext");
    
    0 讨论(0)
  • 2020-12-29 06:15

    "\t" works as well, and "\n" is used to start new line

    0 讨论(0)
  • 2020-12-29 06:21

    You should add tabulator to the text, but \t don't work in settext. The solution is add the character \u0009 that represents in unicode char the tabulator, in a string resource.

    <string name="tab">\u0009</string>
    
    TextView hello = (TextView) findViewById(R.string.helloTextView);
    
    hello.setText("e"+getString(R.string.tab)+"e");
    

    just combine more tab to have more space

    getString(R.string.tab)+getString(R.string.tab)+getString(R.string.tab)
    
    0 讨论(0)
提交回复
热议问题