Code Monkey home page Code Monkey logo

linktextview's Introduction

LinkTextView

Made TextView with ClickableSpan more easy

Download

Gradle

implementation "com.reoobter:linktextview:0.0.4"

Feature

Thanks for VeerHan‘s PR .Now we support match repeat word in some complex scenes. for example

val androidRules = arrayOf("手机", "Linux", "操作系统", "移动设备", "智能手机", "平板电脑", "开放手机联盟")

the word "手机" is repeated in those keyword. when the word "手机" is clicked in ”智能手机“ or ”开发手机联盟“ ,it will be react as "手机” ,while when "智能手机" and ”开发手机联盟“ clicked ,it will react as normal.

Usage

noraml

all clickable word with same color

// the content should be set for TextView
val android = getString(R.string.text_android_baike) 
// Array to define all clickable words
val androidRules = arrayOf("Linux","操作系统","移动设备","智能手机","平板电脑","开放手机联盟") 

Linker.Builder()
    .content(android)
    .textView(text_view_1)
    .links(androidRules)
    .linkColor(ContextCompat.getColor(this,R.color.link))
    .addOnLinkClickListener(onLinkClickListener)
    .apply()

private val onLinkClickListener = object:OnLinkClickListener{
    override fun onClick(view: View, content: String) {
        Toast.makeText(mContext, "clicked link is : $content", Toast.LENGTH_SHORT).show()
    }
}

advance

clickable word with different color

val actorsRules1 = listOf(
    Pair("刘仁娜", ContextCompat.getColor(this, R.color.red)),
    Pair("李栋旭", ContextCompat.getColor(this, R.color.colorPrimary)),
    Pair("吴政世", ContextCompat.getColor(this, R.color.colorAccent)),
    Pair("沈亨倬", ContextCompat.getColor(this, R.color.colorPrimaryDark)),
    Pair("吴义植", ContextCompat.getColor(this, R.color.green)),
    Pair("张基龙", ContextCompat.getColor(this, R.color.blue)),
    Pair("黄灿盛", ContextCompat.getColor(this, R.color.yellow)),
    Pair("金希珍", ContextCompat.getColor(this, R.color.orange))
)

Linker.Builder()
    .content(actors)
    .textView(text_view_4_1)
    .colorLinks(actorsRules1)
    .shouldShowUnderLine(false)
    .addOnLinkClickListener(onLinkClickListener)
    .apply()

API

method function must invocation defaultValue
content content for TextView yes none
textview TextView used for set clickable words yes none
links String/Array/List to define clickable words no none
linkColor Color for clickable word no Color.Black
colorLinks supply a List of Pair,define both word and color no null
shouldShowUnderLine whether to show underline for clickable word no false
addOnLinkClickListener add a listener will callback once click the link word no null
setLinkMovementMethod add a custom LinkMovementMethod no internal
bold true means textStyle="bold" no false
apply apply the function yes none

TODO

  • different color for links

License


Copyright 2019 REBOOTERS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

linktextview's People

Contributors

rebooters avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

linktextview's Issues

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.