开发者

HTML won't be interpreted in my Android project

开发者 https://www.devze.com 2023-03-12 03:57 出处:网络
I\'m facing a strange issue, that I could not fix with the solutions I found on related topics. (through StackOverflow or other sites)

I'm facing a strange issue, that I could not fix with the solutions I found on related topics. (through StackOverflow or other sites)

It is summarized on that StackOverflow topic :

Display HTML Formatted String

So I am asking you. Why the heck is none of those solutions working in my project ?

I even tried to use WebView instead of my TextView ! Nada ! (html tags seem to be simply ignored)

This is my TextView :

<TextView android:layout_height="wrap_content"
an开发者_如何学Pythondroid:layout_width="match_parent" android:id="@+id/signupLinkText"
android:text="" android:gravity="center_horizontal"
android:clickable="true" android:layout_margin="5px"
android:layout_marginTop="10px" android:layout_marginBottom="10px"></TextView>

And the code I use to put my html code

Spanned spannnedSignupLink = Html.fromHtml(getString(R.string.lbl_not_yet_subscribed));
signupLinkText.setText(spannnedSignupLink, BufferType.SPANNABLE);

Then The html that must be interpreted in strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- ... -->
    <string name="lbl_not_yet_subscribed">To sign up to RESA Mobile, <strong>click here</strong> !</string>
</resources>

Thank you for the time you've spent in reading me,

Regards


Post the html your attempting,

This works for me:

 <TextView
        android:id="@+id/message" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:padding="5dip" 
        android:textColor="#FFFFFF" />


  TextView textView = (TextView) findViewById(R.id.message);
  textView.setMovementMethod(LinkMovementMethod.getInstance());
  String message = "Blah blah blah <a href=\"http://google.com\">Google Link</a> blah blah blah.";
  textView.setText(Html.fromHtml(message));


This should work:

TextView textView = findViewById(R.id.signupLinkText);
textView.setText(Html.fromHtml(...put the HTML here...));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号