ColorTextView


Source link: https://github.com/apocalx/colortextview

ColorTextView

Change color of words (or substrings) into a TextView.

This library uses spannable strings to apply colors of the substring (no slow Html.fromHtml or other tricks/hacks)
The ColorTextView class is a direct subclass of TextView, so there are no restrictions, you can still use custom fonts, text size...

Installation

compile 'loic.teillard.colortextview:colortextview:1.0.0' 

Usage

1 - Include ColorTextView namespace to the root element :

xmlns:colortextview="http://schemas.android.com/apk/res-auto" 

2 - Add the ColorTextView with custom params :

<loic.teillard.colortextview.ColorTextView android:layout_width="wrap_content" android:layout_height="wrap_content" colortextview:clt_txt1="Text" colortextview:clt_color1="@color/blue" /> 

The color can be applied from XML or Java (please see sample for good examples) :

XML

Supported Attributs

XML Attribut Description Type
colortextview:clt_txt1 Text of the first part of text String
colortextview:clt_color1 Text color of the first part of text String
colortextview:clt_txt2..10 Text of the next part of text String
colortextview:clt_color2..10 Text color of the next part of text String
colortextview:clt_spaces Automatically add space between each part of text (=word mode, default : false) Boolean

Example

<loic.teillard.colortextview.ColorTextView android:layout_width="wrap_content" android:layout_height="wrap_content" colortextview:clt_spaces="true" colortextview:clt_color1="#5D4037" colortextview:clt_color2="#F4511E" colortextview:clt_txt1="Hello" colortextview:clt_txt2="world !" /> 
Output

Java

Methods

Function Description Comment
addTextColor(String,int) Add text with this color Call it as many times you need to add strings
addTextColorRes(int,int) Add text with this color, both from Resources ID (ex : R.string.text, R.color.blue) Call it as many times you need to add strings
setSpaces(boolean) Automatically add spaces between words no need to add yourself (pass to false if you need to color substring inside a string)
apply() When ready, apply your parameters

Example

ViewGroup layout = (ViewGroup) findViewById(R.id.layout);
  ColorTextView colorTextView = new ColorTextView(this);
  colorTextView.addTextColor("Hello", Color.parseColor("#5D4037"));
 colorTextView.addTextColor("world !", Color.parseColor("#F4511E"));
  colorTextView.setSpaces(true);
  colorTextView.apply();
  layout.addView(colorTextView);
 
Output

Resources

Device Year Class is an Android library that implements a simple algorithm that maps a device's RAM, CPU cores, and clock speed to the year where those combination of specs were considered high end. This allows a developer to easily modify application behavior based on the capabilities of the phone's hardware.

Urc

Uniform Resource Creator is an Android (working for Java-generic) library that helps user to create URLs for RESTful apis.

The path syntax is taken from Slim framework, so it is in the form of /static/:argument.

Provides the Floating Action Button Toolbar as specified in the [Material Design Guide] in a simple library.

Simple way to create link text, such as @username or #hashtag, in Android TextView and EditText

Features:

  • Match single strings or regex pattern to set links
  • Change the color of the linked text
  • Set the underlined of the linked text
  • Specify click actions of a specific word

FloatingView for Android.

A library for Android TV that extends the Leanback library capabilities by offering a set of more powerful features.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes