TextView anchor link space

前端 未结 2 954
时光取名叫无心
时光取名叫无心 2021-01-18 07:42

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(Li         


        
相关标签:
2条回答
  • 2021-01-18 07:59

    // @string/link

    <string name="link1">Test&#160;<a href="#">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.

    0 讨论(0)
  • 2021-01-18 08:07

    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:

    <string name="link">Test <![CDATA[<a href="#">link</a>]]></string>
    
    0 讨论(0)
提交回复
热议问题