开发者

How to change color of hyperlink in android

For displaying hyperlink on a page on my android app I am doing this:

MyProgram.java

l开发者_如何学运维ink1.setText(Html.fromHtml(linkText1));
        link1.setMovementMethod(LinkMovementMethod.getInstance());


        TextView link = (TextView) findViewById(R.id.textView2);
        String linkText = "Visit the <a href='http://www.mydomain.com'>My Website</a> web page.";
        link.setText(Html.fromHtml(linkText));
        link.setMovementMethod(LinkMovementMethod.getInstance());
        // Place email address
        TextView email = (TextView) findViewById(R.id.textView3);
        String emailText = "Contact Me: <a href=\"mailto:myname@mydomain.com\">myname@mydomain.com</a>";
        email.setText(Html.fromHtml(emailText));
        email.setMovementMethod(LinkMovementMethod.getInstance());

myprogram.XML

<TextView android:text="TextView" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="30dp"></TextView>
        <View
        android:layout_width="fill_parent"
        android:layout_height="30dp">
    </View>
        <TextView android:text="TextView" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="30dp"></TextView>

If you see in my XML, I have tried changing the color to black (android:textColor="#000000") but still I don't see any change in the hyperlink. It is still in default color i.e blue

Any Help ?


You should use another attribute:

android:textColorLink="#000000"


Check this code:

    String text = "Visit stackoverflow.com";
    TextView label = new TextView(this);
    label.setText(text);
    Pattern pattern = Pattern.compile("stackoverflow.com");
    Linkify.addLinks(label, pattern, "http://");
    label.setLinkTextColor(Color.CYAN);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜