Smart Text View
Star On GitHub Follow On GitHub
Many applications in android use TextView that detects and highlight various string patterns like emails, phone numbers, web URLs and even hashtags.
This functionality is very common and and is used extensively and frequently in many app. Thus to ease the process of adding this functionality I have authored an Android library SmartTextView.
Find and Star it on GitHub : https://github.com/priyankvex/SmartTextView
Features
- Detect emails, mobile numbers, URLs
- Detect #hash_tags and @mentions
- Use default intents or set custom callbacks.
- Set different colors for each pattern.
Usage
compile 'com.priyankvex:smarttextview:1.0.1'
In layout xml file
<com.wordpress.priyankvex.smarttextview.SmartTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="9pt"
android:id="@+id/textView"
/>
In java Activity or Fragment
mSmartTextView = (SmartTextView) findViewById(R.id.textView);
mSmartTextView.setEmailColorCode("#3cb371");
mSmartTextView.setPhoneNumberColorCode("#ff33aa");
mSmartTextView.setHashTagColorCode("#f37735");
mSmartTextView.setUrlColorCode("#ffc425");
mSmartTextView.setMentionColorCode("#57b884");
mSmartTextView.setDetectMentions(true);
mSmartTextView.setDetectHashTags(true);
mSmartTextView.setText(sampleText);
mSmartTextView.setSmartTextCallback(this);
To use custom callbacks
implements SmartTextCallback
Leave a Reply