All Projects → klinker24 → Android Textview Linkbuilder

klinker24 / Android Textview Linkbuilder

Licence: mit
Insanely easy way to define clickable links within a TextView.

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to Android Textview Linkbuilder

Justifytextview
Deprecated
Stars: ✭ 25 (-98.39%)
Mutual labels:  textview
Leotextview
🐬A high-performance rich editor develop with swift on iOS platform, based on TextKit.
Stars: ✭ 87 (-94.38%)
Mutual labels:  textview
Pincodeinputview
A input text view for entering pin code.
Stars: ✭ 108 (-93.03%)
Mutual labels:  textview
Omegaanimatedtext
Animate bold and italic transformations in TextView
Stars: ✭ 35 (-97.74%)
Mutual labels:  textview
Fole
Fole is a simple library to collapse and expand a TextView.
Stars: ✭ 67 (-95.67%)
Mutual labels:  textview
Aligntextview
字体对齐的textview
Stars: ✭ 1,310 (-15.43%)
Mutual labels:  textview
Roundprogresstextview
TextView with Round Pogress
Stars: ✭ 18 (-98.84%)
Mutual labels:  textview
Pull To Refresh
ESPullToRefresh is developed and maintained by Vincent Li. If you have any questions or issues in using ESPullToRefresh, welcome to issue. If you want to contribute to ESPullToRefresh, Please submit Pull Request, I will deal with it as soon as possible.
Stars: ✭ 1,591 (+2.71%)
Mutual labels:  textview
Ariana
Provide Multiple Gradients in ImageViews and Texts. Integrate with ViewPager to change colors dynamically.
Stars: ✭ 74 (-95.22%)
Mutual labels:  textview
Jhform
JhForm - 自定义表单工具,更加简单,快捷的创建表单、设置页面
Stars: ✭ 108 (-93.03%)
Mutual labels:  textview
Expandabletextview
实现类似微博内容,@用户,链接高亮,@用户和链接可点击跳转,可展开和收回的TextView
Stars: ✭ 992 (-35.96%)
Mutual labels:  textview
Android Material Design In Practice
A project to demonstrate the latest material design principles with simple examples. It has additional examples on how to easily scale texts on different screen sizes without extra effort.
Stars: ✭ 67 (-95.67%)
Mutual labels:  textview
Materialbadgetextview
As the name describes, this is an Android library that you can use to show new messages badge and new features badge.
Stars: ✭ 1,331 (-14.07%)
Mutual labels:  textview
Linkifiedtextview
An extended TextView that allows you to detect several types of links such as urls, hashtags, phone numbers, etc.
Stars: ✭ 9 (-99.42%)
Mutual labels:  textview
Tkkeyboardcontrol
TKKeyboardControl adds keyboard awareness and scrolling dismissal (like iMessages app) to any view with only 1 line of code for Swift.
Stars: ✭ 110 (-92.9%)
Mutual labels:  textview
Android Justifiedtextview
android justified textview
Stars: ✭ 917 (-40.8%)
Mutual labels:  textview
Tagging
A TextView that provides easy to use tagging feature for Mention or Hashtag
Stars: ✭ 91 (-94.13%)
Mutual labels:  textview
Rotatingtext
A periodic text updating library
Stars: ✭ 1,558 (+0.58%)
Mutual labels:  textview
Szmentionsswift
Library to help handle mentions
Stars: ✭ 109 (-92.96%)
Mutual labels:  textview
Nextgrowingtextview
📝 The next in the generations of 'growing textviews' optimized for iOS 8 and above.
Stars: ✭ 1,540 (-0.58%)
Mutual labels:  textview

Android TextView-LinkBuilder Android Arsenal

Screenshot

Insanely easy way to create clickable links within a TextView.

While creating 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.

Features

Similar 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 Strings within a TextView.

  • Specify long and short click actions of a specific word within your TextView
  • Provide user feedback by highlighting the text when the user touches it
  • Match single Strings or use a regular expression to set clickable links to any text conforming to that pattern
  • Change the color of the linked text
  • Change the color of the linked text when the user touches it
  • Modify the transparency of the text's highlighting when the user touches it
  • Set whether or not you want the text underlined
  • Set whether or not you want the text bold
  • Default link color from an activity theme

The 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.

Installation

There are two ways to use this library:

As a Gradle dependency

This is the preferred way. Simply add:

dependencies {
    compile 'com.klinkerapps:link_builder:2.0.5'
}

to your project dependencies and run gradle build or gradle assemble.

As a library project

Download 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.

Example Usage

Functionality can be found in the Kotlin example's MainActivity. For Java check JavaMainActivity.

For a list of regular expressions that I use in Talon, you can go here

// Create the link rule to set what text should be linked.
// can use a specific string or a regex pattern
Link link = new Link("click here")
    .setTextColor(Color.parseColor("#259B24"))                  // optional, defaults to holo blue
    .setTextColorOfHighlightedLink(Color.parseColor("#0D3D0C")) // optional, defaults to holo blue
    .setHighlightAlpha(.4f)                                     // optional, defaults to .15f
    .setUnderlined(false)                                       // optional, defaults to true
    .setBold(true)                                              // optional, defaults to false
    .setOnLongClickListener(new Link.OnLongClickListener() {
        @Override
        public void onLongClick(String clickedText) {
        	// long clicked
        }
    })
    .setOnClickListener(new Link.OnClickListener() {
        @Override
        public void onClick(String clickedText) {
        	// single clicked
        }
    });

TextView demoText = (TextView) findViewById(R.id.test_text);

// create the link builder object add the link rule
LinkBuilder.on(demoText)
    .addLink(link)
    .build(); // create the clickable links

You 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.

// find the text view. Used to create the link builder
TextView demoText = (TextView) findViewById(R.id.test_text);

// Add the links and make the links clickable
CharSequence sequence = LinkBuilder.from(this, demoText.getText().toString())
    .addLinks(getExampleLinks())
    .build();

demoText.setText(sequence);

// if you forget to set the movement method, then your text will not be clickable!
demoText.setMovementMethod(TouchableMovementMethod.getInstance());

If 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.

<style name="LinkBuilderExampleTheme" parent="android:Theme.Holo.Light">
    <item name="linkBuilderStyle">@style/LinkBuilder</item>
</style>
<style name="LinkBuilder">
    <item name="defaultLinkColor">#222222</item>
    <item name="defaultTextColorOfHighlightedLink">#444444</item>
</style>

Kotlin Support

The 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.

val demo = findViewById<TextView>(R.id.demo_text)
demo.applyLinks(link1, link2, ...)
demo.applyLinks(listOfLinks)

Usage with ListView.OnItemClickListener

By 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.

My 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.

Contributing

Please fork this repository and contribute back using pull requests. Features can be requested using issues. All code, comments, and critiques are greatly appreciated.

Changelog

The full changelog for the library can be found here.

License

Copyright 2015 Luke Klinker

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].