A FloatingActionButton subclass that shows a counter badge on right top corner

Overview

License Apache 2.0 minSdkVersion 16 compileSdkVersion 24 CircleCI Download

Android Arsenal CounterFab MaterialUp CounterFab

Icon

CounterFab

A FloatingActionButton subclass that shows a counter badge on right top corner

Sample

Get it on Google Play

It's also used by Louvre library.

Louvre

Installation

Include the library in your build.gradle (check badge at top for latest version)

dependencies{
    compile 'com.github.andremion:counterfab:x.y.z'
}

or in your pom.xml if you are using Maven

<dependency>
  <groupId>com.github.andremion</groupId>
  <artifactId>counterfab</artifactId>
  <version>x.y.z</version>
  <type>pom</type>
</dependency>

Usage

Add it as a regular FloatingActionButton on layout…

<com.andremion.counterfab.CounterFab
        android:id="@+id/counter_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_add_white_24dp" />

and programmatically you can use one of these methods:

CounterFab counterFab = (CounterFab) findViewById(R.id.counter_fab);
counterFab.setCount(10); // Set the count value to show on badge
counterFab.increase(); // Increase the current count value by 1
counterFab.decrease(); // Decrease the current count value by 1

Customization

The recommended way to customize the background color is by using the app:backgroundTint attribute

<com.andremion.counterfab.CounterFab
        android:id="@+id/counter_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:backgroundTint="@color/colorAccent"
        android:src="@drawable/ic_add_white_24dp" />

To change the badge style you can use these attributes:

  • app:badgeBackgroundColor
  • app:badgeTextColor
  • app:badgePosition as RightTop, LeftBottom, LeftTop or RightBottom

For example:

<com.andremion.counterfab.CounterFab
        android:id="@+id/counter_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:badgeBackgroundColor="@color/red"
        app:badgeTextColor="@color/white"
        app:badgePosition="RightTop"
        android:src="@drawable/ic_add_white_24dp" />

See more at the sample

Libraries and tools used in the project

  • Design Support Library The Design package provides APIs to support adding material design components and patterns to your apps.

License

Copyright 2016 André Mion

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.
Comments
  • BadParcelableException still exists in v1.2.0

    BadParcelableException still exists in v1.2.0

    Caused by android.os.BadParcelableException ClassNotFoundException when unmarshalling: android.support.design.stateful.ExtendableSavedState android.os.Parcel.readParcelableCreator (Parcel.java:2326) android.os.Parcel.readParcelable (Parcel.java:2276) android.view.AbsSavedState.<init> (AbsSavedState.java:57) android.view.View$BaseSavedState.<init> (View.java:20245) com.andremion.counterfab.CounterFab$SavedState.<init> (CounterFab.java:306) com.andremion.counterfab.CounterFab$SavedState.<init> (CounterFab.java:291) com.andremion.counterfab.CounterFab$SavedState$1.createFromParcel (CounterFab.java:343) com.andremion.counterfab.CounterFab$SavedState$1.createFromParcel

    bug 
    opened by nickstamp93 9
  • BadParcelableException in 1.1.0

    BadParcelableException in 1.1.0

    CounterFab produces BadParcelableException.

    Caused by: android.os.BadParcelableException: 
      at android.os.Parcel.readParcelableCreator (Parcel.java:2154)
      at android.os.Parcel.readParcelable (Parcel.java:2104)
      at android.view.AbsSavedState.<init> (AbsSavedState.java:57)
      at android.view.View$BaseSavedState.<init> (View.java:19694)
      at com.andremion.counterfab.CounterFab$SavedState.<init> (SourceFile:270)
      at com.andremion.counterfab.CounterFab$SavedState.<init> (SourceFile:255)
      at com.andremion.counterfab.CounterFab$SavedState$1.a (SourceFile:290)
      at com.andremion.counterfab.CounterFab$SavedState$1.createFromParcel (SourceFile:288)
    
    bug 
    opened by alexeyvasilyev 8
  • Unable to update counter value

    Unable to update counter value

    Great library. I am trying to update the value of the counter but can only work on the initial setCount(), subsequent ones are not updating the value. I am currently setting the value at the onCreateView of a fragment where I can increase/decrease the value. However when I come back to the same fragment the new setCount() isn't working because the fragment never got destroyed though onCreateView is called and getCount() shows the value I set but doesn't update the value with the set value. Any advice why this is happening?

    question 
    opened by saintjab 5
  • Badge showing different background color

    Badge showing different background color

    Hi, when I change the counter badge background color using app:badgeBackgroundColor attribute, always badge color showing a darker color than I selected. Example : if I set app:badgeBackgroundColor = "#ffffff", counter icon displaying with a grey color. How can I fix this? Thanks

    question 
    opened by waseem786 4
  • Bug

    Bug

    I just loaded the recent Android update and I am getting this error.

    Invalid drawable added to LayerDrawable! Drawable already belongs to another owner but does not expose a constant state. java.lang.RuntimeException at android.graphics.drawable.LayerDrawable$ChildDrawable.(LayerDrawable.java:1850) at android.graphics.drawable.LayerDrawable$LayerState.(LayerDrawable.java:1967) at android.graphics.drawable.RippleDrawable$RippleState.(RippleDrawable.java:997) at android.graphics.drawable.RippleDrawable.createConstantState(RippleDrawable.java:988) at android.graphics.drawable.RippleDrawable.createConstantState(RippleDrawable.java:986) at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:1774) at android.graphics.drawable.RippleDrawable.mutate(RippleDrawable.java:974) at android.view.View.applyBackgroundTint(View.java:20601) at android.view.View.setBackgroundDrawable(View.java:20472) at android.support.design.widget.FloatingActionButton.access$001(FloatingActionButton.java:69) at android.support.design.widget.FloatingActionButton$ShadowDelegateImpl.setBackgroundDrawable(FloatingActionButton.java:862) at android.support.design.widget.FloatingActionButtonLollipop.setBackgroundDrawable(FloatingActionButtonLollipop.java:73) at android.support.design.widget.FloatingActionButton.(FloatingActionButton.java:188) at com.andremion.counterfab.CounterFab.(CounterFab.java:90) at com.andremion.counterfab.CounterFab.(CounterFab.java:86) at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:334) at android.view.LayoutInflater.createView(LayoutInflater.java:647) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:995) at android.view.LayoutInflater.rInflate(LayoutInflater.java:859) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) at com.hattrick.aformula4success.ordering.Home.onCreate(Home.java:87) at android.app.Activity.performCreate(Activity.java:7009) at android.app.Activity.performCreate(Activity.java:7000) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

    invalid 
    opened by BrianDuncan-HatTrick 4
  • Could you please open the class CounterFab ?

    Could you please open the class CounterFab ?

    If you open the Class CounterFab like below (add the keyword open in front of class) :

    open class CounterFab @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.attr.floatingActionButtonStyle ) : FloatingActionButton(context, attrs, defStyleAttr)

    This will make it easy for others to inherit.

    refactoring 
    opened by StevenMichael3213 3
  • Crash on Android 5.0

    Crash on Android 5.0

    Crash on Android 5.0, ZenPad S 8.0 (Z580CA) This comes from a production user so I don't have an exact reproduction scenario but other versions of Android from the same app haven't reproduced this crash so far. CountraFab version 1.1.1

    Crash log

    Fatal Exception: java.lang.NoSuchMethodError: No direct method <init>(Landroid/os/Parcel;Ljava/lang/ClassLoader;)V in class Landroid/view/View$BaseSavedState; or its super classes (declaration of 'android.view.View$BaseSavedState' appears in /system/framework/framework.jar:classes2.dex)
           at com.andremion.counterfab.CounterFab$SavedState.<init>(CounterFab.java:281)
           at com.andremion.counterfab.CounterFab$SavedState.<init>(CounterFab.java:257)
           at com.andremion.counterfab.CounterFab$SavedState$1.createFromParcel(CounterFab.java:306)
           at com.andremion.counterfab.CounterFab$SavedState$1.createFromParcel(CounterFab.java:302)
           at android.os.Parcel.readParcelable(Parcel.java:2244)
           at android.os.Parcel.readValue(Parcel.java:2146)
           at android.os.Parcel.readSparseArrayInternal(Parcel.java:2540)
           at android.os.Parcel.readSparseArray(Parcel.java:1868)
           at android.os.Parcel.readValue(Parcel.java:2203)
           at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
           at android.os.BaseBundle.unparcel(BaseBundle.java:221)
           at android.os.Bundle.getSparseParcelableArray(Bundle.java:871)
           at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1361)
           at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
           at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
           at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
           at androidx.fragment.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:3223)
           at androidx.fragment.app.Fragment.restoreChildFragmentState(Fragment.java:1526)
           at androidx.fragment.app.Fragment.onCreate(Fragment.java:1497)
           at androidx.navigation.fragment.NavHostFragment.onCreate(NavHostFragment.java:197)
           at androidx.fragment.app.Fragment.performCreate(Fragment.java:2414)
           at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1418)
           at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1684)
           at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3774)
           at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:120)
           at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:405)
           at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:387)
           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
           at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
           at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
           at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
           at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
           at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
           at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
           at com.myapp.MainActivity.onCreate(MainActivity.kt:59)
           at android.app.Activity.performCreate(Activity.java:5975)
           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376)
           at android.app.ActivityThread.access$800(ActivityThread.java:147)
           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
           at android.os.Handler.dispatchMessage(Handler.java:102)
           at android.os.Looper.loop(Looper.java:135)
           at android.app.ActivityThread.main(ActivityThread.java:5253)
           at java.lang.reflect.Method.invoke(Method.java)
           at java.lang.reflect.Method.invoke(Method.java:372)
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)
    
    bug 
    opened by sebaslogen 3
  • Not working

    Not working

    I get this error:

    Error:Execution failed for task ':app:processDebugManifest'.
    > Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be smaller than version 16 declared in library [com.github.andremion:counterfab:1.0.3] /Users/vaevictis/.gradle/caches/transforms-1/files-1.1/counterfab-1.0.3.aar/a29aa8c4f85a075f9eafa82ab292b634/AndroidManifest.xml as the library might be using APIs not available in 15
      	Suggestion: use a compatible library with a minSdk of at most 15,
      		or increase this project's minSdk version to at least 16,
      		or use tools:overrideLibrary="com.andremion.counterfab" to force usage (may lead to runtime failures)
    

    Let me know if I can provide anything else in order to better understand the issues, I am still a nobb at android ;)

    question 
    opened by FrancescoSaverioZuppichini 3
  • implementation 'com.android.support:appcompat-v7:27.1.1' is creating issues

    implementation 'com.android.support:appcompat-v7:27.1.1' is creating issues

    implementation 'com.android.support:appcompat-v7:27.1.1' is not compatible with implementation 'com.github.andremion:counterfab:1.0.1' I got an error

    Program type already present: android.support.design.widget.CoordinatorLayout$Behavior Message{kind=ERROR, text=Program type already present: android.support.design.widget.CoordinatorLayout$Behavior, sources=[Unknown source file], tool name=Optional.of(D8)}

    please help I have to finish it soon

    question 
    opened by Bharatsingh049 2
  • How to custom size image full width and height inside CounterFab

    How to custom size image full width and height inside CounterFab

    <com.andremion.counterfab.CounterFab android:id="@+id/image_view_cart" android:layout_width="32dp" android:layout_height="32dp" android:src="@drawable/shoppingcart" android:layout_alignParentRight="true" android:layout_marginRight="@dimen/margin_8dp" android:layout_centerVertical="true" app:backgroundTint="@null" android:background="@null" android:scaleType="centerCrop"/>

    question 
    opened by NguyenVanLinh2016 2
  • How to configure for scroll recycler view scroll behavior

    How to configure for scroll recycler view scroll behavior

    I added CounterFab over a recycler view. What I want to know is, how can I configure CounterFab to hide when scroll the recycler view? Anyone know any trick? or any methods?

    question 
    opened by waseem786 1
Releases(v1.2.2)
  • v1.2.2(Sep 26, 2019)

    • Add screenshot tests
    • Setup CircleCI
    • Refactoring/convert main source and tests to Kotlin
    • Reuse super state instead of instantiate a new one during the saving instance
    • Apply badge color mask only if there is no badge color defined
    Source code(tar.gz)
    Source code(zip)
  • v1.2.1(Feb 3, 2019)

    • Fix of issue in Xiaomi Mi A2 on Android Pie that makes the text outlined
    • Upgrade to gradle build tools 3.3.0
    • Upgrade to AndroidX
    • Fix of BadParcelableException after restoring state
    • Fix issue in style that makes the ripple effect having a wrong color
    • We can't use FloatingActionButton#setUseCompatPadding anymore due an issue in Lollipop. If you need 16dp margin you only need to define it for Lollipop+.
    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Nov 30, 2018)

  • v1.1.1(Oct 18, 2018)

  • v1.1.0(Sep 11, 2018)

    • Fix icon is overlapped on fabSize mini
    • Add badgeBackgroundColor attribute
    • Update compileSdkVersion and targetSdkVersion to 27
    • Update support library version to 27.1.1
    • Upgrade build gradle tools to 3.1.4
    Source code(tar.gz)
    Source code(zip)
  • v1.0.3(Nov 16, 2017)

  • v1.0.2(Oct 26, 2017)

  • v1.0.1(Feb 3, 2017)

Owner
André Mion
🇧🇷 Android Engineer living in 🇵🇹 • Full time Husband and Dad • Occasionally Drummer and Inline Skater… I build mostly Android stuffs…
André Mion
A simple Floating Action Button that shows an anchored Navigation View

Floating Navigation View A simple Floating Action Button that shows an anchored Navigation View and was inspired by Menu Material Fixed created by Tom

André Mion 1.3k Dec 29, 2022
🛒 Add a cart icon with item counter to the Toolbar. You can increment the counter based on the number of unique items the user has in the shopping cart.

Status CartCounter Add a cart icon with item counter to the Toolbar. You can increment the counter based on the number of unique items the user has in

Rowland Oti 30 Sep 23, 2021
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.

Smart Tool Factory 4 Jul 27, 2022
Material progress circle around any FloatingActionButton. 100% Guidelines.

FABProgressCircle Android library to provide a material progress circle around your FloatingActionButton. This component is compatible with any existe

Jorge Castillo 1.2k Nov 28, 2022
Material progress circle around any FloatingActionButton. 100% Guidelines.

FABProgressCircle Android library to provide a material progress circle around your FloatingActionButton. This component is compatible with any existe

Jorge Castillo 1.2k Jan 7, 2023
TileView is a subclass of android.view.ViewGroup that asynchronously displays, pans and zooms tile-based images. Plugins are available for features like markers, hotspots, and path drawing.

This project isn't maintained anymore. It is now recommended to use https://github.com/peterLaurence/MapView. MapView is maintained by Peter, one of o

Mike Dunn 1.5k Nov 21, 2022
Subclass of ImageView that 'morphs' into a circle shape and can rotates. Useful to be used as album cover in Music apps. :dvd::notes:

Music Cover View A Subclass of ImageView that 'morphs' into a circle shape and can rotates. Useful to be used as album cover in Music apps. It's used

André Mion 254 Dec 23, 2022
TileView is a subclass of android.view.ViewGroup that asynchronously displays, pans and zooms tile-based images. Plugins are available for features like markers, hotspots, and path drawing.

This project isn't maintained anymore. It is now recommended to use https://github.com/peterLaurence/MapView. MapView is maintained by Peter, one of o

Mike Dunn 1.5k Dec 29, 2022
[Development stopped in 2014. Unfinished and not stable - not recommended to use.] An easy-to-use ViewPager subclass with parallax background effect for Android apps.

Development stopped in 2014 Not developed since 2014. Unfinished and not stable - not recommended to use. ParallaxViewPager An easy-to-use ViewPager s

Andras Kindler 437 Dec 29, 2022
Preference subclass that goes into your PreferenceFragment.

IntegrationPreference This library is especially for extension apps developers. Some applications like (Muzei, Series Guide) has extension capabilitie

Said Tahsin Dane 13 Oct 8, 2020
A counter down timer for android which supports both dark and light mode and Persian text and digit.

FlipTimerView A counter down timer for android which supports both dark and light mode and Persian text and digit. English Perisan Getting started Ste

Arezoo Nazer 7 Jul 17, 2022
These files are included in an Android Studio Project for a Magic the Gathering Life Counter app. The app was written in Kotlin.

Magic-Life-Counter These files were created in Android Studio using Kotlin. Usage This app was made to keep track of life totals while playing the tra

null 0 Dec 24, 2021
Dark-souls-overlay - Stream overlay for e.g. a death counter in dark souls

(Dark Souls) Text Overlay Stream-overlay to include in Dark-Souls sessions for e

Florian Mötz 0 Dec 15, 2022
An Islamic "Qadaa" Prayer Counter, purpose of the project is practicing with databases

QadaaCounter-App An app that helps to keep track of Islamic "Qadaa" prayers. It allows you to see when you last changed the amount so you can remember

Burak GIZLICE 1 Oct 15, 2022
Android ImageView that supports different radii on each corner.

SelectableRoundedImageView Note that this project is no longer maintained. Android ImageView that supports different radii on each corner. It also sup

Joonho Kim 1.1k Nov 25, 2022
[Android] Round Corner Progress Bar Library for Android

RoundCornerProgressBar Round corner is cool. Let's make your progress bar to round corner Colorful progress bar with round corner on progress which yo

Akexorcist 2.3k Dec 31, 2022
Android ImageView that supports different radii on each corner.

SelectableRoundedImageView Note that this project is no longer maintained. Android ImageView that supports different radii on each corner. It also sup

Joonho Kim 1.1k Mar 17, 2021
[Android] Round Corner Progress Bar Library for Android

RoundCornerProgressBar Round corner is cool. Let's make your progress bar to round corner Colorful progress bar with round corner on progress which yo

Akexorcist 2.3k Jan 7, 2023
A simple lib to create a ring-like progress view with corner edges

ProgressRingView Installation Gradle: dependencies { compile 'com.github.flepsik:progress-ring-view:1.2.1' } Maven: <dependency> <groupId>com.g

null 71 Dec 5, 2021
Android Fading (Circle/ Custom Corner) Image

Android Fading (Circle/ Custom Corner) Image Implementation add maven { url 'https://jitpack.io' } to build.gradle in your project: allprojects {

Aghiad Odeh 1 Jul 5, 2022