Skip to content Skip to sidebar Skip to footer

Textview Anchor Link Space

I want to make a TextView with a link. I made it with combination of html and bit of java: // used to enable link navigation on TextView setMovementMethod(LinkMovementMethod.getIns

Solution 1:

// @string/link

<stringname="link1">Test&#160;<ahref="#">link</a></string>

You can use the white space in xml as string use &#160;. XML won't take white space as it is. it will trim the white space before setting it. So use &#160; instead of single white space.

Solution 2:

Use CDATA in string to use HTML tags and use Html.fromHtml() method to set the text.

Implementation below:

Set the text using Html.fromHtml() in your Activity class.

TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(Html.fromHtml(getString(R.string.link)));
textView.setMovementMethod(LinkMovementMethod.getInstance());

In strings.xml modify as below:

<stringname="link">Test <![CDATA[<a href="#">link</a>]]></string>

Post a Comment for "Textview Anchor Link Space"