How to change the color of a hyperlink in android studio?

0

I can make Hyperlink perfectly, the problem is that its color is not contrasting well with the background of my application

Iwouldliketoknowhowtomodifyyourcolor,sincechangingthetextcolorofthetextViewdoesnotwork,asthehyperlinkalwaysturnspink.

Activitycode:

package genesysgeneration.font4;

import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.CheckBox;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView tvLink;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tvLink=(TextView)findViewById(R.id.tvLink);
        tvLink.setText(Html.fromHtml("<a href=\"http://www.google.com\">google</a>"));
        tvLink.setMovementMethod(LinkMovementMethod.getInstance());

    }
}

xml da activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/back"
    tools:context="genesysgeneration.font4.MainActivity">

    <TextView
        android:id="@+id/tvLink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="133dp"
        android:text="google"
        android:textColor="#FFFFFF"
        android:textSize="24sp" />
</RelativeLayout>
    
asked by anonymous 19.03.2017 / 23:10

1 answer

2

To change the default color of hyperlink to a TextView , the android:textColorLink attribute is used. You can set the color based on the default color format: #rgb , #argb , #rrggbb or #aarrggbb . See below for how simple it is:

Example in XML:

<TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Um texto qualquer"
        android:textColorLink="#ff0000" />

Example programmatically:

textView.setLinkTextColor(Color.RED);

See more details in documentation (en) .

    
19.03.2017 / 23:36