android strings html,Android: html in strings.xml

Here's most of the examples. I don't think the pre tag is supported.

d10460bed868ce394a2370c6a312651f.png

This is the strings.xml file:

Formatting

<b>Hello World</b> This is a test of the URL <a href="http://www.example.com/">Example</a>

<b>This text is bold</b>

<em>This text is emphasized</em>

This is <sub>subscript</sub> and <sup>superscript</sup>

Here's the layout. Note for the link to actually be clickable, there's a bit of extra work needed:

android:layout_height="fill_parent">

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

android:id="@+id/test1"

android:linksClickable="true"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="12dp"

android:text=""

android:textAppearance="?android:attr/textAppearanceMedium"/>

android:id="@+id/test2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="12dp"

android:text=""

android:textAppearance="?android:attr/textAppearanceMedium"/>

android:id="@+id/test3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="12dp"

android:text=""

android:textAppearance="?android:attr/textAppearanceMedium"/>

android:id="@+id/test4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="12dp"

android:text=""

android:textAppearance="?android:attr/textAppearanceMedium"/>

Finally, the code:

TextView test1 = (TextView)findViewById(R.id.test1);

Spanned spanned = Html.fromHtml(getString(R.string.link));

test1.setMovementMethod(LinkMovementMethod.getInstance());

test1.setText(spanned);

TextView test2 = (TextView)findViewById(R.id.test2);

test2.setText(Html.fromHtml(getString(R.string.bold)));

TextView test3 = (TextView)findViewById(R.id.test3);

test3.setText(Html.fromHtml(getString(R.string.emphasis)));

TextView test4 = (TextView)findViewById(R.id.test4);

test4.setText(Html.fromHtml(getString(R.string.sup)));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值