태그 보관물: TextView

TextView에서 HTML 태그 사용하기

안드로이드에서는 Html.fromHtml()로 TextView에 HTML을 넣는게 가능하다.

TextView tv = (TextView)findViewById(R.id.text);
tv.setText(Html.fromHtml("Text with <br><font color='#ff0000'>Color</font> and <strong>Bold</strong>"));

문자열을 리소스에서 사용하려면 다음처럼 태그를 주의해서 적어야한다.

[strings.xml]

<string name="html_string">Text with &lt;br&gt;&lt;font color=\'#ff0000\'&gt;Color&lt;/font&gt; and &lt;b&gt;Bold&lt;/b&gt;</string>

[TestActivity.java]

TextView tv = (TextView)findViewById(R.id.text);
tv.setText(Html.fromHtml(getResources().getString(R.string.html_string)));