How to use html tag as <b> in android

Asked

Viewed 180 times

0

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

inserir a descrição da imagem aqui

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

description has a string with this text

  • Tries <strong>. (I’m kicking: I’m 0 on Android =)

  • How are you setting the Dialog text? You can demonstrate the code?

  • I made the change

  • http://stackoverflow.com/questions/9935692/how-to-set-part-of-text-to-bold-when-using-alertdialog-setmessage-in-android&#xD; &#xD; See if this helps, I think it’s the same problem.

  • http://stackoverflow.com/questions/8395931/how-to-display-the-html-formatted-text-in-the-popup-box-using-alert-dialog-build

  • @Ilgnerdeoliveira, I updated my answer with your case. Check if it helps you.

Show 1 more comment

2 answers

4


If you want the contents of a TextView, or any other text component is translated as HTML, you should parse the content with Html.fromHtml() before setting the 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();

0

Apparently, you will not only have a dialog with information arranged in this format:

Topic 1

Text of topic 1

Topic 2

Text of topic 2

Topic 3

Text of topic 3

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

text_view_topico_1

text_view_texto_1

text_view_topico_2

text_view_texto_2

text_view_topico_3

text_view_texto_3

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 100 (at least) tags you wrote in each file, but if you use text_views Bast go to the layout, click on text_view, go to properties and change the font, color and type and automatically all dialogs will receive the new configuration parameters.

Browser other questions tagged

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