Thursday, September 24, 2015

// //

Place hyperlink to a website in textview android programmatically

A simple code for placing a link into textview:
add hyperlink to text

MainActivity.java

import android.support.v7.app.ActionBarActivity;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;


public class MainActivity extends ActionBarActivity {

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

        TextView link = (TextView) findViewById(R.id.hyper);
        String linkText = "This is my website Programondaspot .";
        link.setText(Html.fromHtml(linkText));
        link.setMovementMethod(LinkMovementMethod.getInstance());
    
    }

    
    
}



And in your activity_main.xml


    




HAPPY CODING!