Coder Social home page Coder Social logo

ozzie00 / android-actionitembadge Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mikepenz/android-actionitembadge

0.0 3.0 0.0 564 KB

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

Home Page: http://mikepenz.github.io/Android-ActionItemBadge

License: Apache License 2.0

Java 100.00%

android-actionitembadge's Introduction

#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 {
	compile('com.mikepenz:actionitembadge:2.5.0@aar') {
	    transitive = true
	}
}

If you want to use this library with the old ActionBar. Do the following.

dependencies {
	compile 'com.tundem.actionitembadge:library:1.2.0@aar'
}

You use ActionbarSherlock? No problem there's now a SNAPSHOT release for ActionbarSherlock. Just do the following:

Add the SNAPSHOT repo to your repositories:

        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }

And the compile dependency

dependencies {
	compile 'com.tundem.actionitembadge:library-abs:1.2.0@aar'
}

##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_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.BadgeStyle.DARKGREY, 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 ActionItemBadge.Add().act(this).menu(menu).title(R.string.sample_2).itemDetails(0, SAMPLE2_ID, 1).showAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS).build(ActionItemBadge.BadgeStyle.BLUE_LARGE, 1);
        return true;
    }

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--;
            invalidateOptionsMenu();
            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 2015 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.

android-actionitembadge's People

Contributors

gitter-badger avatar mikepenz avatar mohamedmenasy avatar tral avatar

Watchers

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