appsfeature / better-linkify

A simple android widget extending the textview to handle hyperlinks,emails and mobile tags. Feel free you use it as you wish

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BetterLinkify

When android:autoLink="all" or Linkify.addLinks(textView, Linkify.ALL) is used to add links to web URLs, phone-numbers, map addresses or email addresses in a TextView, Android uses a class known as LinkMovementMethod that handles highlighting links when they're focused and dispatching an Intent when they're clicked.

Hyperlinks are not working with Linkify.addLinks(Linkify.ALL) method, which is now fixed in our library.

BetterLinkify improves over Hyperlinks, like shown below:

String yourText = "Clicks are reported across all platforms. 
        Learn more <a href='https://www.google.com'><strong>Click here</strong></a> 
        <p><br>Please contact us on:- 
        <br><br>MobileNo:9891983694 
        <br>Email-ID:alpha@gmail.com <br>
        <br>Reference:http://google.com</p>";

Preview 1

Setup Project

Add this to your project build.gradle

Project-level build.gradle (/build.gradle):

allprojects {
    repositories {
        google()
        jcenter() 
        maven { url 'https://jitpack.io' } 
    } 
}

Add this to your project build.gradle

Module-level build.gradle (/build.gradle):

dependencies {
    implementation 'com.github.appsfeature:better-linkify:x.y'
} 

In your layout.xml file:

<com.linkify.TextViewLinkify
    android:id="@+id/tv_linkify"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

In your activity class:

public class MainActivity extends AppCompatActivity {

    String yourText = "Clicks are reported across all platforms. Learn more <a href='https://www.google.com'><strong>Click here</strong></a> <p><br>Please contact us on:- <br><br>MobileNo:9891983694 <br>Email-ID:alpha@gmail.com <br><br>Reference:http://google.com</p>";

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

        TextViewLinkify tvDesc = findViewById(R.id.tv_post);

        tvDesc.setText(getTextData());
        tvDesc.addLinks(Linkify.ALL);
    }

    private CharSequence getTextData() {
        return LinkifyUtil.loadHtmlData(LinkifyUtil.htmlData(yourText));
    }

}
                                

About

A simple android widget extending the textview to handle hyperlinks,emails and mobile tags. Feel free you use it as you wish


Languages

Language:Java 100.0%