How to put line break in the textview straight from xml?

Asked

Viewed 5,999 times

4

inserir a descrição da imagem aqui

wanted to put this text more organized without creating several textview , and I had the idea of using line break .

2 answers

5


Use the escape character \n:

android:text="linha1\nlinha2\nlinha3"
  • there is some example when the text is dynamic to break the line?

1

You can add HTML tags to your text strings.html

follows an example:

html strings.

 <string name="minha_receita_1"> <![CDATA[ <ul> <li>1 caneca ou bule</li> <li>1 garrafa térmica</li> <li>1 colher (sopa)</li> <li> 1 coador de café</li> </ul> ]]> </string>

The content html should be among <![CDATA[ ]]>

In java do the following:

     TextView textHtml = TextView.class.cast(convertView.findViewById(R.id.receita));
    final Spanned textoEmHtml = Html.fromHtml( getContext().getString(R.string.minha_receita_1));
    textHtml.setText(textoEmHtml);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.