{"id":13428185,"url":"https://github.com/klinker24/Android-TextView-LinkBuilder","last_synced_at":"2025-03-16T01:32:01.545Z","repository":{"id":34152857,"uuid":"37991744","full_name":"klinker24/Android-TextView-LinkBuilder","owner":"klinker24","description":"Insanely easy way to define clickable links within a TextView.","archived":false,"fork":false,"pushed_at":"2020-01-20T00:09:39.000Z","size":542,"stargazers_count":1588,"open_issues_count":11,"forks_count":200,"subscribers_count":43,"default_branch":"master","last_synced_at":"2024-08-01T01:28:09.303Z","etag":null,"topics":["android","clickable-links","java","textview"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/klinker24.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-24T15:04:40.000Z","updated_at":"2024-07-20T15:34:26.000Z","dependencies_parsed_at":"2022-07-13T21:34:29.000Z","dependency_job_id":null,"html_url":"https://github.com/klinker24/Android-TextView-LinkBuilder","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klinker24%2FAndroid-TextView-LinkBuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klinker24%2FAndroid-TextView-LinkBuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klinker24%2FAndroid-TextView-LinkBuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klinker24%2FAndroid-TextView-LinkBuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klinker24","download_url":"https://codeload.github.com/klinker24/Android-TextView-LinkBuilder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221631876,"owners_count":16855020,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","clickable-links","java","textview"],"created_at":"2024-07-31T01:00:48.597Z","updated_at":"2024-10-27T05:30:47.973Z","avatar_url":"https://github.com/klinker24.png","language":"Kotlin","readme":"# Android TextView-LinkBuilder [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-TextView--LinkBuilder-green.svg?style=flat)](https://android-arsenal.com/details/1/2049)\n\n![Screenshot](preview.png)\n\nInsanely easy way to create clickable links within a `TextView`.\n\nWhile creating [Talon for Twitter](https://github.com/klinker24/Talon-for-Twitter), one of the most difficult things I encountered was creating these clickable links based on specific text. Luckily, I have made it easy for anyone to apply this type of style to their `TextView`'s.\n\n## Features\n\nSimilar to how all the big players do it (Google+, Twitter, *cough* Talon *cough*), this library allows you to create clickable links for any combination of `String`s within a `TextView`.\n\n - Specify long and short click actions of a specific word within your `TextView`\n - Provide user feedback by highlighting the text when the user touches it\n - Match single `String`s or use a regular expression to set clickable links to any text conforming to that pattern\n - Change the color of the linked text\n - Change the color of the linked text when the user touches it\n - Modify the transparency of the text's highlighting when the user touches it\n - Set whether or not you want the text underlined\n - Set whether or not you want the text bold\n - Default link color from an activity theme\n\nThe main advantage to using this library over `TextView`'s autolink functionality is that you can link anything, not just web address, emails, and phone numbers. It also provides color customization and touch feedback.\n\n## Installation\n\nThere are two ways to use this library:\n\n#### As a Gradle dependency\n\nThis is the preferred way. Simply add:\n\n```groovy\ndependencies {\n    compile 'com.klinkerapps:link_builder:2.0.5'\n}\n```\n\nto your project dependencies and run `gradle build` or `gradle assemble`.\n\n#### As a library project\n\nDownload the source code and import it as a library project in Eclipse. The project is available in the folder **library**. For more information on how to do this, read [here](http://developer.android.com/tools/projects/index.html#LibraryProjects).\n\n## Example Usage\n\nFunctionality can be found in the Kotlin example's [MainActivity](https://github.com/klinker24/Android-TextView-LinkBuilder/blob/master/example/src/main/java/com/klinker/android/link_builder_example/MainActivity.kt). For Java check [JavaMainActivity](https://github.com/klinker24/Android-TextView-LinkBuilder/blob/master/example/src/main/java/com/klinker/android/link_builder_example/JavaMainActivity.java).\n\nFor a list of regular expressions that I use in Talon, you can go [here](https://github.com/klinker24/Talon-for-Twitter/blob/master/app/src/main/java/com/klinker/android/twitter/utils/text/Regex.java)\n\n```java\n// Create the link rule to set what text should be linked.\n// can use a specific string or a regex pattern\nLink link = new Link(\"click here\")\n    .setTextColor(Color.parseColor(\"#259B24\"))                  // optional, defaults to holo blue\n    .setTextColorOfHighlightedLink(Color.parseColor(\"#0D3D0C\")) // optional, defaults to holo blue\n    .setHighlightAlpha(.4f)                                     // optional, defaults to .15f\n    .setUnderlined(false)                                       // optional, defaults to true\n    .setBold(true)                                              // optional, defaults to false\n    .setOnLongClickListener(new Link.OnLongClickListener() {\n        @Override\n        public void onLongClick(String clickedText) {\n        \t// long clicked\n        }\n    })\n    .setOnClickListener(new Link.OnClickListener() {\n        @Override\n        public void onClick(String clickedText) {\n        \t// single clicked\n        }\n    });\n\nTextView demoText = (TextView) findViewById(R.id.test_text);\n\n// create the link builder object add the link rule\nLinkBuilder.on(demoText)\n    .addLink(link)\n    .build(); // create the clickable links\n```\n\nYou can also create a `CharSequence` instead of creating and applying the links directly to the `TextView`. Do not forget to set the movement method on your `TextView`'s after you have applied the `CharSequence`, or else the links will not be clickable.\n\n```java\n// find the text view. Used to create the link builder\nTextView demoText = (TextView) findViewById(R.id.test_text);\n\n// Add the links and make the links clickable\nCharSequence sequence = LinkBuilder.from(this, demoText.getText().toString())\n    .addLinks(getExampleLinks())\n    .build();\n\ndemoText.setText(sequence);\n\n// if you forget to set the movement method, then your text will not be clickable!\ndemoText.setMovementMethod(TouchableMovementMethod.getInstance());\n```\n\nIf you would like to set the default text color for links without inputting it manually on each `Link` object, it can be set from the activity theme.\n\n```xml\n\u003cstyle name=\"LinkBuilderExampleTheme\" parent=\"android:Theme.Holo.Light\"\u003e\n    \u003citem name=\"linkBuilderStyle\"\u003e@style/LinkBuilder\u003c/item\u003e\n\u003c/style\u003e\n\u003cstyle name=\"LinkBuilder\"\u003e\n    \u003citem name=\"defaultLinkColor\"\u003e#222222\u003c/item\u003e\n    \u003citem name=\"defaultTextColorOfHighlightedLink\"\u003e#444444\u003c/item\u003e\n\u003c/style\u003e\n```\n\n## Kotlin Support\n\nThe library is built on Kotlin, so you get some extension methods that you can use to apply the links to the `TextView`, instead of creating the builder.\n\n```kotlin\nval demo = findViewById\u003cTextView\u003e(R.id.demo_text)\ndemo.applyLinks(link1, link2, ...)\ndemo.applyLinks(listOfLinks)\n```\n\n## Usage with ListView.OnItemClickListener\n\nBy default, `LinkBuilder` will consume all the touch events on your `TextView`. This means that `ListView.OnItemClickListener` will never get called if you try to implement it. The fix for this is to implement the `LinkConsumableTextView` rather than the normal TextView in your layouts.\n\nMy `LinkConsumableTextView` will only consume touch events if you have clicked the link within the `TextView`. Otherwise, it will defer the touch event to the parent, which allows you to use `ListView.OnItemClickListener` method.\n\n## Contributing\n\nPlease fork this repository and contribute back using [pull requests](https://github.com/klinker24/Android-TextView-LinkBuilder/pulls). Features can be requested using [issues](https://github.com/klinker24/Android-TextView-LinkBuilder/issues). All code, comments, and critiques are greatly appreciated.\n\n## Changelog\n\nThe full changelog for the library can be found [here](https://github.com/klinker24/Android-TextView-LinkBuilder/blob/master/changelog.md).\n\n\n## License\n\n    Copyright 2015 Luke Klinker\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":["Libraries","TextView","Java","Kotlin"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklinker24%2FAndroid-TextView-LinkBuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklinker24%2FAndroid-TextView-LinkBuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklinker24%2FAndroid-TextView-LinkBuilder/lists"}