项目作者: UmairKhalid786

项目描述 :
A light weight library which handles multiple colors in a single TextView for Android.
高级语言: Java
项目地址: git://github.com/UmairKhalid786/ColorStrings.git
创建时间: 2018-06-30T20:22:03Z
项目社区:https://github.com/UmairKhalid786/ColorStrings

开源协议:MIT License

下载


ColorStrings

A light weight library which handles multiple colors in a single TextView for Android.

How to

To get this project into your build:

Step 1

Open project level gradle file
Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io'}
  5. }
  6. }

Step 1

Open app module gradle file and add the dependency

  1. dependencies {
  2. implementation 'com.github.UmairKhalid786:ColorStrings:1.0.1'
  3. }

How to use it ?

After following above mentioned steps you are ready to code , Sample code is pasted from example given in this repo.

  1. TextView textView = (TextView) findViewById(R.id.attributed_tv);
  2. List<ColoredString> coloredStringsList = new ArrayList<>();
  3. //Add create your colored String objects
  4. ColoredString coloredString1 = new ColoredString(Color.BLACK , "Hello ");
  5. ColoredString coloredString2 = new ColoredString(Color.RED , "Colored ");
  6. ColoredString coloredString3 = new ColoredString(Color.BLACK , "World");
  7. //add them to array of this objects
  8. coloredStringsList.add(coloredString1);
  9. coloredStringsList.add(coloredString2);
  10. coloredStringsList.add(coloredString3);
  11. //And then call this function to get SpannableStringBuilder
  12. SpannableStringBuilder builder = StringPainter.getColoredText(coloredStringsList);
  13. //Set this builder to textView without converting using toString() method on builder
  14. textView.setText(builder , BufferType.SPANNABLE);

Output

smoutput