/ Badge View

Add badge with counter to ImageView Android

Add badge with counter to ImageView Android

ImageBadgeView

Library to add ImageView (ImageBadgeView) with a badge like notification count.

Download

Add to gradle root:

buildscript {
    repositories {
        jcenter()
    }
}

Download via Gradle:

implementation 'com.github.nikartm:image-support:1.0.5'

or Maven:

<dependency>
  <groupId>com.github.nikartm</groupId>
  <artifactId>image-support</artifactId>
  <version>1.0.5</version>
  <type>pom</type>
</dependency>

Screenshots

sct_1

How to use?

Adjust the xml view More examples.:

<ru.nikartm.support.ImageBadgeView
    android:id="@+id/ibv_icon2"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_marginTop="30dp"
    android:layout_gravity="center"
    android:padding="10dp"
    app:ibv_badgeValue="100"
    app:ibv_badgeTextSize="12sp"
    app:ibv_fixedBadgeRadius="15dp"
    app:ibv_badgeTextStyle="bold"
    app:ibv_badgeTextColor="#ffffff"
    app:ibv_badgeColor="#00ACC1"
    app:ibv_badgeLimitValue="false"
    android:src="@drawable/ic_shopping_cart" />

Or programmatically:

imageBadgeView.setBadgeValue(27)
        .setBadgeOvalAfterFirst(true)
        .setBadgeTextSize(16)
        .setMaxBadgeValue(999)
        .setBadgeTextFont(typeface)
        .setBadgeBackground(getResources().getDrawable(R.drawable.rectangle_rounded))
        .setBadgePosition(BadgePosition.BOTTOM_RIGHT)
        .setBadgeTextStyle(Typeface.NORMAL)
        .setShowCounter(true)
        .setBadgePadding(4);

Change the position of a badge on view:

app:ibv_badgePosition="bottom_right"

Use the custom badge background:

app:ibv_badgeBackground="@drawable/rectangle_rounded"

Example the custom background - rectangle_rounded.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="#ea5444"/>
    <corners android:radius="24dp"/>

    <stroke
        android:width="1dp"
        android:color="#f5f5f5"/>
</shape>

GitHub