Srini
Srini

Reputation: 1639

how to use HTML tags to format text in an EditText in android

my code looks like this

txtData=(EditText)findViewById(R.id.textbox);
txtData.setText(Html.fromHtml("<b><html></b>"));

as you can see i am trying to make HTML code appear in an EditText box. I am trying to use HTML tags using the Html.fromHtml() method to format the HTML code that appears in the box. i need to find a way to escape the '<' and '>' tags around the word html from being processed by the fromHtml method. any suggestions on how to do this ?

Upvotes: 1

Views: 1271

Answers (3)

Diego Torres Milano
Diego Torres Milano

Reputation: 69198

You should use

 &lt; 

and

 &gt;

as in this example

txtData.setText(Html.fromHtml("<b>&lt;html&gt;</b>"));

Upvotes: 1

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132972

try this:

txtData=(EditText)findViewById(R.id.textbox);
txtData.setText(Html.fromHtml("<b>&#60;html&#62;</b>"));

or

txtData=(EditText)findViewById(R.id.textbox);
txtData.setText(Html.fromHtml("<b>&lt;html&gt;</b>"));

Upvotes: 1

Niko
Niko

Reputation: 8153

Try this:

txtData.setText(Html.fromHtml("<b>&#60;html&#62;<b>"));

Upvotes: 1

Related Questions