Code Monkey home page Code Monkey logo

colortextview's Introduction

MultiColorTextView

引用

在gradle中引用:

implementation 'com.dreamlin.colortextview:colortextview:1.0.0'

属性

属性 说明 示例
app:colors 颜色串,默认使用 '|'字符分割 "#FF0000|#00FF00|#0000FF"
app:texts 字符串,默认使用'|'字符分割 "愿你风尘仆仆|深情不被辜负|虽回不到过去|也回不到当初"
app:defColor 默认颜色,不指定默认为黑色 "#FFC125"
app:spilt 分隔符,默认为字符'|' "="、"|"等

使用

支持两种方式:

在xml中使用

<com.dreamlin.colortextview.MultiColorTextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dp"
    android:textSize="13sp"
    app:colors="#FF8C00|#FF1493|#FFC0CB|"
    app:defColor="#0D0D0D"
    app:texts="最孤独是读评论区未署名情书|
    像不小心掀开了时光的典故|
    第十是睁开眼就已黄昏迟暮|
    寒星三两落在远远处" />

默认使用字符|进行分割,当然你也可以通过spilt属性指定分隔符

在代码中使用

tvSetText.setColorTexts("第五是骑单车过陌生的马路|在拥挤的人海中踌躇|第四是给空白的纸上画上五线谱|每一行都好像是世界的遗嘱", "#548B54|#6959CD|#76EEC6|#7EC0EE")

除此之外,还支持在代码中替换匹配文字的颜色:

  • 单字符串匹配修改颜色
//注意使用该方法会使其他文字颜色失效
tvRegexOne.applyColorForText("一", "#FF7F24")
  • 多字符串匹配修改颜色
tvRegexMulti.applyColorForTexts(new String[]{"#FF6EB4", "#FF83FA", "#FF4500"}, "愿你风尘仆仆", "虽回不到过去", "愿你风雨落幕能有人免你孤独")

具体效果可查看Demo

colortextview's People

Contributors

struggledreamlin avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.