How to use html tag like b in android

0

I have a text and I put it in a dialog, how do I not keep appearing the tag, but the effect of it

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
        alertDialogBuilder.setMessage(listenerItem.descricao);
        alertDialogBuilder.setPositiveButton(R.string.voltar,null);
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();

In description has a String with this text

    
asked by anonymous 26.03.2015 / 19:27

2 answers

4

If you want the content of a TextView , or any other text component to be translated as HTML , you should parse the content with Html.fromHtml () before setting text :

Example:

myTextView.setText(Html.fromHtml("<h2>Titulo</h2><p><b>Paragrafo com texto em negrito (bold)</b></p>"));

In your case:

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
        // altere essa linha
        alertDialogBuilder.setMessage(Html.fromHtml(listenerItem.descricao));
        alertDialogBuilder.setPositiveButton(R.string.voltar,null);
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    
26.03.2015 / 19:40
0

It seems that you will not only have a dialog with information arranged in this format:

Topic 1

Topic 1 text

Topic 2

Topic 2 Text

Topic 3

Topic 3 Text

Right? If this is the case, I think it would be better to create a default layout with text_views as follows:

text_view_topico_1

text_view_text_1

text_view_topico_2

text_view_text_2

text_view_topico_3

text_view_text_3

Well imagine that you want to change the font, color and type of the topic. If you have 100 text files, you would have to edit all of the 100 (minimum) tags you wrote in each file, but if you use text_views to go in the layout, click the text_view, go to properties and change the font, color and type and automatically all dialogs will receive the new configuration parameters.

    
26.03.2015 / 21:40