• Stars
    star
    1,275
  • Rank 35,353 (Top 0.8 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 10 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Android-ActionItemBadge Maven Central Android Arsenal

Join the chat at https://gitter.im/mikepenz/Android-ActionItemBadge

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

Screenshots

Image Image

Include in your project

Using Maven

The ActionItemBadge Library is pushed to [Maven Central], so you just need to add the following dependency to your build.gradle.

dependencies {
	implementation 'com.mikepenz:actionitembadge:4.0.0'

	//SUB-DEPENDENCIES
	//Android-Iconics - used to provide an easy API for icons 
	implementation 'com.mikepenz:iconics-core:{latestVersion}@aar'
}

Additional dependency for the icon font

If you are going to use the icon font you will have to add additional dependency for the font. You can find all available addons here: https://github.com/mikepenz/Android-Iconics#2-choose-your-desired-fonts

UPGRADE NOTES

< 4.0.0

  • If you come from a version prior 4.0.0 you will have to upgrade to AndroidX and Iconics v4

< 3.0.0

  • If you come from a version prior 3.0.0 you will have to rename some classes, and the default styles also found a new place. Just check out the updated sample app for all the changes.

Usage

menu.xml

Create your menu.xml as you would do normally and add the app:actionLayout param. It is also a good idea to set showAsAction="always" (The badge can only be shown in the actionbar)

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/item_samplebadge"
        app:actionLayout="@layout/menu_action_item_badge"
        app:showAsAction="always"
        android:title="@string/sample_1"/>
</menu>

Activity

Override the onCreateOptionsMenu method

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

	    //you can add some logic (hide it if the count == 0)
        if (badgeCount > 0) {
            ActionItemBadge.update(this, menu.findItem(R.id.item_samplebadge), FontAwesome.Icon.faw_android, ActionItemBadge.BadgeStyles.DARK_GREY, badgeCount);
        } else {
            ActionItemBadge.hide(menu.findItem(R.id.item_samplebadge));
        }

	    //If you want to add your ActionItem programmatically you can do this too. You do the following:
        new ActionItemBadgeAdder().act(this).menu(menu).title(R.string.sample_2).itemDetails(0, SAMPLE2_ID, 1).showAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS).add(bigStyle, 1);
        return super.onCreateOptionsMenu(menu);
    }

If you want to update the item itself you can do the required stuff in the onOptionsItemSelected method and call invalidateOptionsMenu() afterwards.

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.item_samplebadge) {
            Toast.makeText(this, R.string.sample_3, Toast.LENGTH_SHORT).show();
            badgeCount--;
            ActionItemBadge.update(item, badgeCount);
            return true;
        } else if (id == SAMPLE2_ID) {
            Toast.makeText(this, R.string.sample_4, Toast.LENGTH_SHORT).show();
        }
        return super.onOptionsItemSelected(item);
    }

Dependencies

Developed By

License

Copyright 2019 Mike Penz

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

MaterialDrawer

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
Kotlin
11,656
star
2

Android-Iconics

Android-Iconics - Use any icon font, or vector (.svg) as drawable in your application.
Kotlin
5,136
star
3

FastAdapter

The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
Kotlin
3,789
star
4

AboutLibraries

AboutLibraries automatically collects all dependencies and licenses of any gradle project (Kotlin MultiPlatform), and provides easy to integrate UI components for Android and Compose-jb environments
Kotlin
3,442
star
5

LollipopShowcase

A simple app to showcase Androids Material Design and some of the cool new cool stuff in Android Lollipop. RecyclerView, CardView, ActionBarDrawerToggle, DrawerLayout, Animations, Android Compat Design, Toolbar
Java
1,762
star
6

wallsplash-android

wall:splash is a free open source android client for the awesome unsplash.com service (Free (do whatever you want) high-resolution photos)
Java
791
star
7

release-changelog-builder-action

A GitHub action that builds your release notes / changelog fast, easy and exactly the way you want.
TypeScript
643
star
8

ItemAnimators

ItemAnimators: Supercharged Animators for your RecyclerView
Java
339
star
9

Materialize

A easy helper library for Android to manage your applications StatusBarShadow, FullScreen behavior and much more over API Levels down to 10
Java
295
star
10

multiplatform-markdown-renderer

Markdown renderer for Kotlin Multiplatform Projects (Android, iOS, Desktop), using Compose.
Kotlin
260
star
11

action-junit-report

Reports junit test results as GitHub Pull Request Check
TypeScript
258
star
12

AnimatedGridView

A simple library which adds some basic animation if you delete fields. There's also a HeaderGridView if you need such a view for your projects :D
Java
116
star
13

CrossfadeDrawerLayout

Add a 2-Step DrawerLayout to your application, with a nice crossfade effect
Java
96
star
14

Crossfader

Crossfader is a small library to provide an easy to use and fast helper class for the great CrossFadeSlidingPaneLayout
Java
80
star
15

gradle-dependency-submission

Calculates dependencies for a Gradle build-target and submits the list to the Dependency Submission API
TypeScript
77
star
16

xray-action

... a GitHub action to import test results into "Xray" - A complete Test Management tool for Jira.
TypeScript
41
star
17

ModernJenkins-Theme

A quick css to beautify your jenkins (SimpleThemePlugin required)
CSS
20
star
18

storyblok-mp-SDK

Storyblok Kotlin Multiplatform SDK (Android, JVM, JS, iOS, ...)
Kotlin
20
star
19

HoloKitKatDrawer

[DEPRECATED] See for the MaterialDrawer for updates | Description: A simple Project to show how to use the new TranslucentDecor with a Drawer
Java
14
star
20

Storyblok-Android-SDK

Storyblok MP SDK available here: https://github.com/mikepenz/storyblok-mp-SDK
Kotlin
14
star
21

ApplicationReader

[DEPRECATED] OpenSourced source code for ApplicationReader util used for icon themeing
Java
9
star
22

Alternative-findr

[DEPRECATED!] Android application for the awesome site alternative.to
Java
6
star
23

storyblok-mp-SDK-sample

Storyblok Kotlin Multiplatform SDK sample (Android, JVM, JS)
Kotlin
6
star
24

storyblok-mp-SDK-blog

Blog implemented via the Storyblok Kotlin Multiplatform SDK (Android, JVM)
Kotlin
5
star
25

jira-release-composite-action

Composite action, taking release notes as input, and automatically migrating tickets for release
4
star
26

blog_CredentialShowcase

Simple showcase to highlight credential security
Kotlin
2
star
27

SpannableBar

Java
2
star
28

teaMSeven-MOD

[DEPRECATED] A smart tool for our awesome teaMSeven Kernel!
Java
1
star
29

InterfaceLIFT-Pane

An InterfaceLIFT Preference Pane for Mac OS X
Objective-C
1
star
30

MIcons-Builder

[DEPRECATED] MIUI Icons Builder/Configurator
JavaScript
1
star
31

release-changelog-builder-action-playground

Playground repo for testing purposes of the release-changelog-builder-action
1
star