Git Product home page Git Product logo

badge's Introduction

Badge

Apache 2.0 License Release

Preview

Integration

  • Add the JitPack repository to your root build.gradle:
repositories {
    maven { url "https://jitpack.io" }
}
  • Add the dependency to your sub build.gradle:
dependencies {
    implementation "com.github.nekocode:Badge:${last-version}"
}

Badge Types

This library provides four types of badges with cliche customizations.

Type Badge Type Badge
TYPE_NUMBER number TYPE_ONLY_ONE_TEXT single
TYPE_TWO_TEXT two TYPE_TWO_TEXT_COMPLEMENTARY complementary

Attributes

Usage

The above screenshot's example:

final BadgeDrawable drawable =
        new BadgeDrawable.Builder()
                .type(BadgeDrawable.TYPE_NUMBER)
                .number(9)
                .build();

final BadgeDrawable drawable2 =
        new BadgeDrawable.Builder()
                .type(BadgeDrawable.TYPE_ONLY_ONE_TEXT)
                .badgeColor(0xff336699)
                .text1("VIP")
                .build();

final BadgeDrawable drawable3 =
        new BadgeDrawable.Builder()
                .type(BadgeDrawable.TYPE_WITH_TWO_TEXT_COMPLEMENTARY)
                .badgeColor(0xffCC9933)
                .text1("LEVEL")
                .text2("10")
                .padding(dp2px(2), dp2px(2), dp2px(2), dp2px(2), dp2px(2))
                .strokeWidth(dp2px(1))
                .build();

final BadgeDrawable drawable4 =
        new BadgeDrawable.Builder()
                .type(BadgeDrawable.TYPE_WITH_TWO_TEXT)
                .badgeColor(0xffCC9999)
                .text1("TEST")
                .text2("Pass")
                .build();

final BadgeDrawable drawable5 =
        new BadgeDrawable.Builder()
                .type(BadgeDrawable.TYPE_NUMBER)
                .number(999)
                .badgeColor(0xff336699)
                .build();

The above drawable4 BadgeDrawable has set a number that too large to show, in this case, it will be replaced with "..." for showing. And then you can use toSpannable() for converting the drawable to SpannableString without setting its drawing bounds. It has already took internal measure.

SpannableString spannableString =
        new SpannableString(TextUtils.concat(
                "TextView ",
                drawable.toSpannable(),
                " ",
                drawable2.toSpannable(),
                " ",
                drawable3.toSpannable(),
                " ",
                drawable4.toSpannable(),
                " ",
                drawable5.toSpannable()
        ));

textView.setText(spannableString);

If the drawable's bounds was setted by manual or content view. It will auto cut the text to adjust the bounds' width. Look like:

You can also use the badge drawable for ImageView and other more view.

badge's People

Contributors

nekocode avatar ashik94vc 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.