Coder Social home page Coder Social logo

outlinespan's Introduction

OutlineSpan

Library (just one class) for outlining TextView.

How to use

Use android's Spannable class for changing style of part of text.

val outlineSpan = OutlineSpan(
    strokeColor = Color.RED,
    strokeWidth = 4F
)
val text = "Outlined text"
val spannable = SpannableString(text)
spannable.setSpan(outlineSpan, 0, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

// Set text of TextView
binding.outlinedText.text = spannable 

Result:

Download (Gradle)

Add Jitpack repository:

repositories {
    maven { url 'https://jitpack.io' }
}

Add dependency:

dependencies {
    implementation 'com.github.santaevpavel:OutlineSpan:0.1.1'
}

If you don't want to add dependency, you can copy class OutlineSpan to your project.

Sample

Link

outlinespan's People

Contributors

santaevpavel avatar

Stargazers

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

Watchers

 avatar  avatar

outlinespan's Issues

When set span on whole text the text becomes invisible

I am setting the span on whole text but there is a problem if a set it on complete text length then the text becomes invisible.

spannableString.setSpan(testSpan,0,txt.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
If i set like this then it works:
spannableString.setSpan(testSpan,2,txt.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
just set srtart to any other numbe than 0.

OutlineSpan with StaticLayout and less width

I am using this OutlineSpan with StaticLayout.

It works fine when I pass the width to the static layout by measuring like that

StaticLayout.getDesiredWidth(txt, textPaint);

But When i set less width than the actual width that will wrap the text then It is the property of static layout that it automatically increases the number of lines of the text and keeps the width the one that we provide.

But when I use OutlineSpan and decrease the width it doesn't increase the number of lines instead it just draw the text with its complete width that will wrap the text.

In short, using OutlineSpan and StaticLayout with less width does not affect anything it just draws the text with actual width.

I hope you will understand my problem if you have worked with StaticLayout. Otherwise please ask me questions.
Thanks

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.