BadgeCounter icon indicating copy to clipboard operation
BadgeCounter copied to clipboard

A simple library for show a counter in action menu, based https://github.com/mikepenz/Android-ActionItemBadge

BadgeCounter Download

A simple library for show a badge counter in action menu.

BadgeCounter BadgeCounter BadgeCounter How to use

compile 'com.github.juanlabrador:badgecounter:1.0.2@aar'

menu.xml

Add in your menu.xml, app:actionLayout="@layout/badge_counter" param.

  <menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" tools:context=".DemoActivity">

    <item android:id="@+id/action_settings"
        android:title="@string/action_settings"
        android:orderInCategory="100"
        app:showAsAction="never" />

    <item
        android:id="@+id/notification"
        android:title="Notification"
        app:actionLayout="@layout/badge_counter"
        app:showAsAction="always"/>
</menu>

Activity

  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_demo, menu);

        // Create a condition (hide it if the count == 0)
        if (mNotificationCounter > 0) {
            BadgeCounter.update(this,
                    menu.findItem(R.id.notification),
                    R.mipmap.ic_notification,
                    BadgeCounter.BadgeColor.BLUE,
                    mNotificationCounter);
        } else {
            BadgeCounter.hide(menu.findItem(R.id.notification));
        }

        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        } else if (id == R.id.notification) {
            // If you want to update
            mNotificationCounter--;
            BadgeCounter.update(item, mNotificationCounter);
        }

        return super.onOptionsItemSelected(item);
    }

You can set an icon drawable or icon res, textColor just in white (for now), and you change color to badge (Defaul is RED). Remember the specific sizes for these types of icons, you can use https://romannurik.github.io/AndroidAssetStudio/icons-generic.html

Log

v1.0.2

  • Adjust in xml

v1.0

  • TextColor in badge is just white
  • Change background badge color
  • setIcon with drawable or resource

Developed by

Inspiration in

Android-ActionItemBadge