:octocat: Drawable of badge.

Related tags

UI/UX android widget
Overview

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.

You might also like...
A FloatingActionButton subclass that shows a counter badge on right top corner
A FloatingActionButton subclass that shows a counter badge on right top corner

CounterFab A FloatingActionButton subclass that shows a counter badge on right top corner It's also used by Louvre library. Installation Include the l

BadgedImageview allow you show a badge into a Imageview.
BadgedImageview allow you show a badge into a Imageview.

BadgedImageview BadgedImageview allow you show a badge into a Imageview. I just extracted the widgets from Plaid app developed by Nick Butcher(https:/

An Android library supports badge notification like iOS in Samsung, LG, Sony and HTC launchers.
An Android library supports badge notification like iOS in Samsung, LG, Sony and HTC launchers.

ShortcutBadger: The ShortcutBadger makes your Android App show the count of unread messages as a badge on your App shortcut! Supported launchers: Sony

[] A simple way to
[] A simple way to "badge" any given Android view at runtime without having to cater for it in layout

Android ViewBadger A simple way to "badge" any given Android view at runtime without having to cater for it in layout. Note: If your aim is to replica

This library offers a simple method to add a small badge icon to your ActionBar-MenuItem
This library offers a simple method to add a small badge icon to your ActionBar-MenuItem

Android-ActionItemBadge ActionItemBadge is a library which offers a simple and easy to use method to add a badge to your action item! Screenshots Incl

🗻 Unopinionated, easy-to-use, and customizable Badge component for Jetpack Compose
🗻 Unopinionated, easy-to-use, and customizable Badge component for Jetpack Compose

Cobadge 🗻 Unopinionated, easy-to-use, and customizable Badge component for Jetpack Compose Getting started In this section I will walk you through th

Dynamic Badge with customizable features as max number before displaying with +, color, shadow, border, corner radius, font properties and more written with Jetpack Compose
Dynamic Badge with customizable features as max number before displaying with +, color, shadow, border, corner radius, font properties and more written with Jetpack Compose

✏️📌 Dynamic Badge with customizable features as max number before displaying with +, color, shadow, border, corner radius, font properties and more written with Jetpack Compose. Displays numbers either in circle or rounded rectangle shape based on badge count and selected threshold to transform from circle to rounded rectangle.

Visual back-port of the rotating drawer-to-arrow drawable from Android L
Visual back-port of the rotating drawer-to-arrow drawable from Android L

DrawerArrowDrawable A simple drawable backport of the new drawer-indicator/back-arrow rotating drawable from the upcoming Android L. License Copyright

This light-weight library provides images with letter/text like the Gmail app. It extends the Drawable class thus can be used with existing/custom/network ImageView classes. Also included is a fluent interface for creating drawables and a customizable ColorGenerator. A wave-like loading drawable
A wave-like loading drawable

#WaveLoading This library provides a wave loading animation as a Drawable. How to use Add dependency: compile 'com.race604.waveloading:library:1.1.1'

Library containing over 2000 material vector icons that can be easily used as Drawable or as a standalone View.
Library containing over 2000 material vector icons that can be easily used as Drawable or as a standalone View.

Material Icon Library A library containing over 2000 material vector icons that can be easily used as Drawable, a standalone View or inside menu resou

🕹️ See how the properties of Android's
🕹️ See how the properties of Android's "shape" affect the Drawable's appearance, intuitively.

GradientDrawableTuner English | 中文 Get confusing about the drawable in Android? Try playing with GradientDrawableTuner! With the GradientDrawableTuner

PaintableVectorView enables to change color of paths/groups in Vector Drawable (SVG)
PaintableVectorView enables to change color of paths/groups in Vector Drawable (SVG)

PaintableVectorView PaintableVectorView enables to change color of paths/groups in Vector Drawable (SVG) Demo Car icon made by Prosymbols from www.fla

PlayPauseDrawable 1.9 0.0 L5 Java This is a sample Play & Pause Drawable with morphing animation for Android
PlayPauseDrawable 1.9 0.0 L5 Java This is a sample Play & Pause Drawable with morphing animation for Android

#PlayPauseDrawable #Deprecated please go to https://github.com/tarek360/Material-Animation-Samples This is a sample Play & Pause Drawable with morphin

Android-Iconics - Use any icon font, or vector (.svg) as drawable in your application.
Android-Iconics - Use any icon font, or vector (.svg) as drawable in your application.

Android-Iconics ... allows to include any icon font with all its vector icons in your project. No limits. Scale with no limit, use any color at any ti

This light-weight library provides images with letter/text like the Gmail app. It extends the Drawable class thus can be used with existing/custom/network ImageView classes. Also included is a fluent interface for creating drawables and a customizable ColorGenerator. Visual back-port of the rotating drawer-to-arrow drawable from Android L
Visual back-port of the rotating drawer-to-arrow drawable from Android L

DrawerArrowDrawable A simple drawable backport of the new drawer-indicator/back-arrow rotating drawable from the upcoming Android L. License Copyright

Drawable animation inspired by Tinder.
Drawable animation inspired by Tinder.

WaveDrawable Drawable animation inspired by Tinder. Download compile 'me.alexrs:wave-drawable:1.0.0' LinearInterpolator BounceInterpolator CycleInterp

Android Studio plugin which automatically generates drawable selectors from appropriately named resources.
Android Studio plugin which automatically generates drawable selectors from appropriately named resources.

SelectorChapek for Android This Android Studio plugin automatically generates drawable selectors from appropriately named Android resources. How to in

Comments
  • Added ability to change typeface

    Added ability to change typeface

    The library is so awesome but I missed the ability to change typeface. So I added the endpoint to change typeface in this cute and beautiful library. So the changes are,

    • New Builder typeFace(Typeface tf) method where the tf can be any custom typeface.
    opened by ashik94vc 1
  • Use Unicode ellipsis instead of three dots

    Use Unicode ellipsis instead of three dots

    Replace "..." with "…".

    http://www.fileformat.info/info/unicode/char/2026/index.htm

    BadgeDrawable.java:266

    private String cutNumber(int number, int width) {
        String text = String.valueOf(number);
        return this.paint.measureText(text) < (float)width?text:"...";
    }
    
    private String cutText(String text, int width) {
        if(this.paint.measureText(text) <= (float)width) {
            return text;
        } else {
            String suffix = "...";
            // ...
            return text + suffix;
        }
    }
    
    opened by consp1racy 0
  • Added new Badge type

    Added new Badge type

    • Added support for Android 7.0
    • Dependencies added for latest build tools.
    • Renamed badge TYPE_WITH_TWO_TEXT to TYPE_WITH_TWO_TEXT complementary
    • Added badge TYPE_WITH_TWO_TEXT which has same text and background color for both text with badgeColor as border
    opened by ashik94vc 0
Owner
nekocode
I'm a full-stack engineer and specialize in frontend (android/flutter/web) development.
nekocode
[] A simple way to "badge" any given Android view at runtime without having to cater for it in layout

Android ViewBadger A simple way to "badge" any given Android view at runtime without having to cater for it in layout. Note: If your aim is to replica

Jeff Gilfelt 3k Nov 28, 2022
This library offers a simple method to add a small badge icon to your ActionBar-MenuItem

Android-ActionItemBadge ActionItemBadge is a library which offers a simple and easy to use method to add a badge to your action item! Screenshots Incl

Mike Penz 1.3k Jan 1, 2023
IconicDroid is a custom Android Drawable which allows to draw icons from several iconic fonts.

IconicDroid IconicDroid is a custom Android Drawable which allows to draw icons from several iconic fonts. Try out the sample application on the Googl

Artur Termenji 387 Nov 20, 2022
🛠️ The missing drawable toolbox for Android. Create drawables programmatically and get rid of the boring and always repeated drawable.xml files.

DrawableToolbox English | 中文 The missing DrawableToolbox for Android. Create drawables programmatically and get rid of the boring and always repeated

Hong Duan 1.1k Jan 4, 2023
Some beautiful android loading drawable, can be combined with any view as the LoadingView or the ProgressBar. Besides, some Drawable can customize the loading progress too.

LoadingDrawable: Android cool animation collection 前言 CircleRotate源码解析 Fish源码解析 LoadingDrawable is some android animations implement of drawable: a li

dinus_developer 4.1k Dec 27, 2022
:octocat: ≡ DirectSelect is a selection widget with an ethereal, full-screen modal popup displaying the available choices when the widget is interact with.

DIRECT SELECT [JAVA] Selection widget with an ethereal, full-screen modal popup displaying the available choices We specialize in the designing and co

Ramotion 536 Nov 22, 2022
:octocat: Navigation toolbar is a slide-modeled UI navigation controller made by @Ramotion

NAVIGATION TOOLBAR Navigation toolbar is a Kotlin slide-modeled UI navigation controller. We specialize in the designing and coding of custom UI for M

Ramotion 804 Dec 9, 2022
:octocat: A demo project based on MVVM architecture and material design & animations.

GithubFollows A simple demo project based on MVVM clean architecture and material design & animations. Architecture Specs & Open-source libraries Mini

Jaewoong Eum 288 Dec 25, 2022
:octocat: 📃 FoldingCell is a material design expanding content cell inspired by folding paper material made by @Ramotion

FOLDING CELL [JAVA] Expanding content cell with animation inspired by folding paper card material design. We specialize in the designing and coding of

Ramotion 4.9k Dec 7, 2022
:octocat: A demo project based on MVVM architecture and material design & animations.

GithubFollows A simple demo project based on MVVM clean architecture and material design & animations. Architecture Specs & Open-source libraries Mini

Jaewoong Eum 289 Jan 4, 2023