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

Asked

Viewed 464 times

0

I can do Hyperlink perfectly, the problem is that your color is not contrasting well with the background of my application (follows picture):

inserir a descrição da imagem aqui

I would like to know how to change your color, since changing the text color of the textView does not work, because the hyperlink always turns pink.

Code of the Activity:

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 by 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>

1 answer

2


To change the default color of the hyperlink in a TextView the attribute is used android:textColorLink. You can set the color based on the default color format: #rgb, #argb, #rrggbb or #aarrggbb. See below 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" />

Programmatic example:

textView.setLinkTextColor(Color.RED);

See more details in the documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.