项目作者: HseinNd98

项目描述 :
Easiest and fastest way to implement Clickable Spans for Android. Adding regular Clickable Spans in Android requires calculating sizes for each clickable text, and when it comes to adding a lot of clickable and regular words or sentences in a TextView is becomes a mess..
高级语言: Java
项目地址: git://github.com/HseinNd98/SmartClickableSpan.git
创建时间: 2020-09-20T11:26:03Z
项目社区:https://github.com/HseinNd98/SmartClickableSpan

开源协议:Apache License 2.0

下载


SmartClickableSpan

Easiest and fastest way to implement Clickable Spans for Android.
Adding regular Clickable Spans in Android requires calculating sizes for each clickable text, and when it comes to adding a lot of clickable and regular words or sentences in a TextView is becomes a mess..
By using SmartClickableSpan, you’ll be able to add whatever amount of clickable words or sentences without any worries of calculating length of each text on every update on it.

Download

To implement SmartClickableSpan in your project:

Using Gradle:

Step 1. Add JitPack in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency:

  1. dependencies {
  2. implementation 'com.github.HseinNd98:SmartClickableSpan:v0.1.5'
  3. }

Using Maven:

Step 1. Add the JitPack repository to your build file:

  1. <repositories>
  2. <repository>
  3. <id>jitpack.io</id>
  4. <url>https://jitpack.io</url>
  5. </repository>
  6. </repositories>

Step 2. Add the dependency:

  1. <dependency>
  2. <groupId>com.github.HseinNd98</groupId>
  3. <artifactId>SmartClickableSpan</artifactId>
  4. <version>0.1.5</version>
  5. </dependency>

How do I use SmartClickableSpan?

Single clickable text:

  1. new SmartClickableSpan
  2. .Builder(this)
  3. .regularText("I agree to all ")
  4. .clickableText(new ClickableOptions().setText("Terms of Use").setOnClick(new ClickableSpan() {
  5. @Override
  6. public void onClick(@NonNull View view) {
  7. // Your Code..
  8. }
  9. }))
  10. .into(myTextView);

More clickable texts:

  1. new SmartClickableSpan
  2. .Builder(this)
  3. .regularText("I agree to all ")
  4. .clickableText(new ClickableOptions().setText("Terms of Use").setOnClick(new ClickableSpan() {
  5. @Override
  6. public void onClick(@NonNull View view) {
  7. // Your Code..
  8. }
  9. }))
  10. .regularText(" and ")
  11. .clickableText(new ClickableOptions().setText("Privacy Policy").setOnClick(new ClickableSpan() {
  12. @Override
  13. public void onClick(@NonNull View view) {
  14. // Your Code..
  15. }
  16. }))
  17. .into(myTextView);

Customizing:

  1. ClickableOptions clickableOptions = new ClickableOptions();
  2. clickableOptions.setColor(Color.BLUE);
  3. clickableOptions.setText("terms and conditions");
  4. clickableOptions.setOnClick(new ClickableSpan() {
  5. @Override
  6. public void onClick(@NonNull View view) {
  7. // Your Code..
  8. }
  9. @Override
  10. public void updateDrawState(@NonNull TextPaint ds) {
  11. // Customizing your clickable text
  12. ds.setUnderlineText(false);
  13. ds.setColor(Color.BLUE);
  14. //...
  15. }
  16. });
  17. new SmartClickableSpan
  18. .Builder(this)
  19. .regularText("I agree to all ")
  20. .clickableText(clickableOptions)
  21. .into(myTextView);

Optional useful methods:

  • autoSpacing() Adds space automatically every time a new text is added, which helps to keep the sentence well formed. (Default: false)
  • setHighlightColor(int color) Removes highlight color on clickable texts. (Default: Color.Transparent)

Compatibility:

  • Minimum Android SDK: requires a minimum API level of 15

Applications using this library: