Badge count on Floating action button












6















I would like to show count badge in front of Floating Action Button in android. I used FrameLayout in order to achieve that. My code is here



   <FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/send_button"
android:layout_toLeftOf="@+id/send_button"
android:layout_toStartOf="@+id/send_button"
android:layout_gravity="end|bottom"
android:id="@+id/frameLayout">

<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/listen_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:backgroundTint="#e3e3e3" />

<TextView
android:id="@+id/textOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:textColor="#FFF"
android:textSize="10sp"
android:textStyle="bold"
android:background="@drawable/badge_circle"
android:layout_gravity="right|bottom"
android:layout_alignBottom="@+id/frameLayout"
android:layout_toLeftOf="@+id/frameLayout"
android:layout_toStartOf="@+id/frameLayout" />

</FrameLayout>


I get the count badge below the FAB, as shown below



enter image description here



I need the count badge to be in front of the FAB.










share|improve this question

























  • From the design guidelines: "Floating action buttons don’t contain app bar icons or status bar notifications. Don’t layer badges or other elements over a floating action button." google.com/design/spec/components/…

    – Daniel Nugent
    Jun 5 '16 at 8:14











  • Try android:layout_alignParentTop="true" and android:layout_alignParentLeft="true" for both elements.

    – Ali Sheikhpour
    Jun 5 '16 at 8:16
















6















I would like to show count badge in front of Floating Action Button in android. I used FrameLayout in order to achieve that. My code is here



   <FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/send_button"
android:layout_toLeftOf="@+id/send_button"
android:layout_toStartOf="@+id/send_button"
android:layout_gravity="end|bottom"
android:id="@+id/frameLayout">

<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/listen_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:backgroundTint="#e3e3e3" />

<TextView
android:id="@+id/textOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:textColor="#FFF"
android:textSize="10sp"
android:textStyle="bold"
android:background="@drawable/badge_circle"
android:layout_gravity="right|bottom"
android:layout_alignBottom="@+id/frameLayout"
android:layout_toLeftOf="@+id/frameLayout"
android:layout_toStartOf="@+id/frameLayout" />

</FrameLayout>


I get the count badge below the FAB, as shown below



enter image description here



I need the count badge to be in front of the FAB.










share|improve this question

























  • From the design guidelines: "Floating action buttons don’t contain app bar icons or status bar notifications. Don’t layer badges or other elements over a floating action button." google.com/design/spec/components/…

    – Daniel Nugent
    Jun 5 '16 at 8:14











  • Try android:layout_alignParentTop="true" and android:layout_alignParentLeft="true" for both elements.

    – Ali Sheikhpour
    Jun 5 '16 at 8:16














6












6








6


1






I would like to show count badge in front of Floating Action Button in android. I used FrameLayout in order to achieve that. My code is here



   <FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/send_button"
android:layout_toLeftOf="@+id/send_button"
android:layout_toStartOf="@+id/send_button"
android:layout_gravity="end|bottom"
android:id="@+id/frameLayout">

<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/listen_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:backgroundTint="#e3e3e3" />

<TextView
android:id="@+id/textOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:textColor="#FFF"
android:textSize="10sp"
android:textStyle="bold"
android:background="@drawable/badge_circle"
android:layout_gravity="right|bottom"
android:layout_alignBottom="@+id/frameLayout"
android:layout_toLeftOf="@+id/frameLayout"
android:layout_toStartOf="@+id/frameLayout" />

</FrameLayout>


I get the count badge below the FAB, as shown below



enter image description here



I need the count badge to be in front of the FAB.










share|improve this question
















I would like to show count badge in front of Floating Action Button in android. I used FrameLayout in order to achieve that. My code is here



   <FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/send_button"
android:layout_toLeftOf="@+id/send_button"
android:layout_toStartOf="@+id/send_button"
android:layout_gravity="end|bottom"
android:id="@+id/frameLayout">

<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/listen_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:backgroundTint="#e3e3e3" />

<TextView
android:id="@+id/textOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
android:textColor="#FFF"
android:textSize="10sp"
android:textStyle="bold"
android:background="@drawable/badge_circle"
android:layout_gravity="right|bottom"
android:layout_alignBottom="@+id/frameLayout"
android:layout_toLeftOf="@+id/frameLayout"
android:layout_toStartOf="@+id/frameLayout" />

</FrameLayout>


I get the count badge below the FAB, as shown below



enter image description here



I need the count badge to be in front of the FAB.







android android-layout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 5 '16 at 8:33









Håken Lid

10.8k62643




10.8k62643










asked Jun 5 '16 at 7:57









Feras AlTuraigiFeras AlTuraigi

3113




3113













  • From the design guidelines: "Floating action buttons don’t contain app bar icons or status bar notifications. Don’t layer badges or other elements over a floating action button." google.com/design/spec/components/…

    – Daniel Nugent
    Jun 5 '16 at 8:14











  • Try android:layout_alignParentTop="true" and android:layout_alignParentLeft="true" for both elements.

    – Ali Sheikhpour
    Jun 5 '16 at 8:16



















  • From the design guidelines: "Floating action buttons don’t contain app bar icons or status bar notifications. Don’t layer badges or other elements over a floating action button." google.com/design/spec/components/…

    – Daniel Nugent
    Jun 5 '16 at 8:14











  • Try android:layout_alignParentTop="true" and android:layout_alignParentLeft="true" for both elements.

    – Ali Sheikhpour
    Jun 5 '16 at 8:16

















From the design guidelines: "Floating action buttons don’t contain app bar icons or status bar notifications. Don’t layer badges or other elements over a floating action button." google.com/design/spec/components/…

– Daniel Nugent
Jun 5 '16 at 8:14





From the design guidelines: "Floating action buttons don’t contain app bar icons or status bar notifications. Don’t layer badges or other elements over a floating action button." google.com/design/spec/components/…

– Daniel Nugent
Jun 5 '16 at 8:14













Try android:layout_alignParentTop="true" and android:layout_alignParentLeft="true" for both elements.

– Ali Sheikhpour
Jun 5 '16 at 8:16





Try android:layout_alignParentTop="true" and android:layout_alignParentLeft="true" for both elements.

– Ali Sheikhpour
Jun 5 '16 at 8:16












6 Answers
6






active

oldest

votes


















3














As suggested by Daniel, you should not add badges to Floating Action Buttons. However, if you really have to do it, try adding this property to your TextView:



android:elevation="7dp"





share|improve this answer

































    2














    I used the CounterFab library to achieve this.



    It is as simple as adding it to your XML layout file instead of the regular FloatingActionButton and calling counterFab.setCount(10); (See usage example here).






    share|improve this answer


























    • It isn't working fine for Android 6.0 or lower versions.

      – Weaboo
      Jun 10 '18 at 7:41



















    1














    One can simply use TextView by giving custom style for floating.



            <TextView
    android:id="@+id/fabCounter"
    style="@style/Widget.Design.FloatingActionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_centerVertical="true"
    android:layout_marginEnd="10dp"
    android:padding="5dp"
    android:text="10"
    android:textColor="@android:color/black"
    android:textSize="14sp" />



    Result







    share|improve this answer































      1














      For this problem solution is android:elevation="7dp". But you are looking for something like this then use bellow code:



      enter image description here



      <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      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"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
      <RelativeLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentRight="true"
      android:layout_alignParentBottom="true"
      android:layout_margin="@dimen/margin.2">
      <android.support.design.widget.FloatingActionButton
      android:id="@+id/fab_cart"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:layout_alignParentRight="true"
      android:layout_margin="@dimen/margin.2"
      app:srcCompat="@drawable/ic_add_shopping_cart"
      app:backgroundTint="@color/colorPrimaryDark" />
      <TextView
      android:id="@+id/text_count"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:elevation="7dp"
      android:gravity="center"
      android:textColor="@color/white"
      android:layout_alignParentRight="true"
      android:textSize="@dimen/text.size.small"
      android:background="@drawable/bg_fab"
      tools:text="10" />
      </RelativeLayout>
      </RelativeLayout>





      share|improve this answer































        0














        Give it a Try :



        <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|left"
        app:layout_anchor="@+id/containerpager"
        app:layout_anchorGravity="bottom|right">

        <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:elevation="0dp"
        android:visibility="visible"
        app:backgroundTint="@color/colorPrimary"
        app:borderWidth="0dp"
        app:fabSize="normal"
        app:srcCompat="@drawable/ic_review_order" />

        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="5"
        android:textColor="@color/white"
        android:textSize="22sp"
        android:visibility="visible" />
        </RelativeLayout>





        share|improve this answer































          -2














          try this changes:



          <FrameLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="end|bottom"
          android:id="@+id/frameLayout">

          <android.support.design.widget.FloatingActionButton
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:id="@+id/listen_button"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:src="@android:color/transparent"
          app:backgroundTint="#e3e3e3" />

          <TextView
          android:id="@+id/textOne"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="10"
          android:textColor="#FFF"
          android:textSize="10sp"
          android:textStyle="bold"
          android:background="@drawable/badge_circle"/>

          </FrameLayout>





          share|improve this answer
























          • not working on RelativeLayout.

            – Md Imran Choudhury
            May 25 '17 at 9:21











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37639698%2fbadge-count-on-floating-action-button%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          6 Answers
          6






          active

          oldest

          votes








          6 Answers
          6






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          As suggested by Daniel, you should not add badges to Floating Action Buttons. However, if you really have to do it, try adding this property to your TextView:



          android:elevation="7dp"





          share|improve this answer






























            3














            As suggested by Daniel, you should not add badges to Floating Action Buttons. However, if you really have to do it, try adding this property to your TextView:



            android:elevation="7dp"





            share|improve this answer




























              3












              3








              3







              As suggested by Daniel, you should not add badges to Floating Action Buttons. However, if you really have to do it, try adding this property to your TextView:



              android:elevation="7dp"





              share|improve this answer















              As suggested by Daniel, you should not add badges to Floating Action Buttons. However, if you really have to do it, try adding this property to your TextView:



              android:elevation="7dp"






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 23 '18 at 10:31









              Rohit5k2

              14.3k42551




              14.3k42551










              answered Aug 10 '16 at 13:30









              LucaLuca

              312




              312

























                  2














                  I used the CounterFab library to achieve this.



                  It is as simple as adding it to your XML layout file instead of the regular FloatingActionButton and calling counterFab.setCount(10); (See usage example here).






                  share|improve this answer


























                  • It isn't working fine for Android 6.0 or lower versions.

                    – Weaboo
                    Jun 10 '18 at 7:41
















                  2














                  I used the CounterFab library to achieve this.



                  It is as simple as adding it to your XML layout file instead of the regular FloatingActionButton and calling counterFab.setCount(10); (See usage example here).






                  share|improve this answer


























                  • It isn't working fine for Android 6.0 or lower versions.

                    – Weaboo
                    Jun 10 '18 at 7:41














                  2












                  2








                  2







                  I used the CounterFab library to achieve this.



                  It is as simple as adding it to your XML layout file instead of the regular FloatingActionButton and calling counterFab.setCount(10); (See usage example here).






                  share|improve this answer















                  I used the CounterFab library to achieve this.



                  It is as simple as adding it to your XML layout file instead of the regular FloatingActionButton and calling counterFab.setCount(10); (See usage example here).







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 26 '17 at 15:19

























                  answered Apr 15 '17 at 20:32









                  TomerTomer

                  2,1271721




                  2,1271721













                  • It isn't working fine for Android 6.0 or lower versions.

                    – Weaboo
                    Jun 10 '18 at 7:41



















                  • It isn't working fine for Android 6.0 or lower versions.

                    – Weaboo
                    Jun 10 '18 at 7:41

















                  It isn't working fine for Android 6.0 or lower versions.

                  – Weaboo
                  Jun 10 '18 at 7:41





                  It isn't working fine for Android 6.0 or lower versions.

                  – Weaboo
                  Jun 10 '18 at 7:41











                  1














                  One can simply use TextView by giving custom style for floating.



                          <TextView
                  android:id="@+id/fabCounter"
                  style="@style/Widget.Design.FloatingActionButton"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_alignParentEnd="true"
                  android:layout_centerVertical="true"
                  android:layout_marginEnd="10dp"
                  android:padding="5dp"
                  android:text="10"
                  android:textColor="@android:color/black"
                  android:textSize="14sp" />



                  Result







                  share|improve this answer




























                    1














                    One can simply use TextView by giving custom style for floating.



                            <TextView
                    android:id="@+id/fabCounter"
                    style="@style/Widget.Design.FloatingActionButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_centerVertical="true"
                    android:layout_marginEnd="10dp"
                    android:padding="5dp"
                    android:text="10"
                    android:textColor="@android:color/black"
                    android:textSize="14sp" />



                    Result







                    share|improve this answer


























                      1












                      1








                      1







                      One can simply use TextView by giving custom style for floating.



                              <TextView
                      android:id="@+id/fabCounter"
                      style="@style/Widget.Design.FloatingActionButton"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_alignParentEnd="true"
                      android:layout_centerVertical="true"
                      android:layout_marginEnd="10dp"
                      android:padding="5dp"
                      android:text="10"
                      android:textColor="@android:color/black"
                      android:textSize="14sp" />



                      Result







                      share|improve this answer













                      One can simply use TextView by giving custom style for floating.



                              <TextView
                      android:id="@+id/fabCounter"
                      style="@style/Widget.Design.FloatingActionButton"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_alignParentEnd="true"
                      android:layout_centerVertical="true"
                      android:layout_marginEnd="10dp"
                      android:padding="5dp"
                      android:text="10"
                      android:textColor="@android:color/black"
                      android:textSize="14sp" />



                      Result








                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 18 '17 at 5:24









                      Aks4125Aks4125

                      2,76111233




                      2,76111233























                          1














                          For this problem solution is android:elevation="7dp". But you are looking for something like this then use bellow code:



                          enter image description here



                          <?xml version="1.0" encoding="utf-8"?>
                          <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                          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"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent">
                          <RelativeLayout
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_alignParentRight="true"
                          android:layout_alignParentBottom="true"
                          android:layout_margin="@dimen/margin.2">
                          <android.support.design.widget.FloatingActionButton
                          android:id="@+id/fab_cart"
                          android:layout_width="wrap_content"
                          android:layout_height="match_parent"
                          android:layout_alignParentRight="true"
                          android:layout_margin="@dimen/margin.2"
                          app:srcCompat="@drawable/ic_add_shopping_cart"
                          app:backgroundTint="@color/colorPrimaryDark" />
                          <TextView
                          android:id="@+id/text_count"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:elevation="7dp"
                          android:gravity="center"
                          android:textColor="@color/white"
                          android:layout_alignParentRight="true"
                          android:textSize="@dimen/text.size.small"
                          android:background="@drawable/bg_fab"
                          tools:text="10" />
                          </RelativeLayout>
                          </RelativeLayout>





                          share|improve this answer




























                            1














                            For this problem solution is android:elevation="7dp". But you are looking for something like this then use bellow code:



                            enter image description here



                            <?xml version="1.0" encoding="utf-8"?>
                            <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                            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"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">
                            <RelativeLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignParentRight="true"
                            android:layout_alignParentBottom="true"
                            android:layout_margin="@dimen/margin.2">
                            <android.support.design.widget.FloatingActionButton
                            android:id="@+id/fab_cart"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:layout_alignParentRight="true"
                            android:layout_margin="@dimen/margin.2"
                            app:srcCompat="@drawable/ic_add_shopping_cart"
                            app:backgroundTint="@color/colorPrimaryDark" />
                            <TextView
                            android:id="@+id/text_count"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:elevation="7dp"
                            android:gravity="center"
                            android:textColor="@color/white"
                            android:layout_alignParentRight="true"
                            android:textSize="@dimen/text.size.small"
                            android:background="@drawable/bg_fab"
                            tools:text="10" />
                            </RelativeLayout>
                            </RelativeLayout>





                            share|improve this answer


























                              1












                              1








                              1







                              For this problem solution is android:elevation="7dp". But you are looking for something like this then use bellow code:



                              enter image description here



                              <?xml version="1.0" encoding="utf-8"?>
                              <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                              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"
                              android:layout_width="match_parent"
                              android:layout_height="match_parent">
                              <RelativeLayout
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_alignParentRight="true"
                              android:layout_alignParentBottom="true"
                              android:layout_margin="@dimen/margin.2">
                              <android.support.design.widget.FloatingActionButton
                              android:id="@+id/fab_cart"
                              android:layout_width="wrap_content"
                              android:layout_height="match_parent"
                              android:layout_alignParentRight="true"
                              android:layout_margin="@dimen/margin.2"
                              app:srcCompat="@drawable/ic_add_shopping_cart"
                              app:backgroundTint="@color/colorPrimaryDark" />
                              <TextView
                              android:id="@+id/text_count"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:elevation="7dp"
                              android:gravity="center"
                              android:textColor="@color/white"
                              android:layout_alignParentRight="true"
                              android:textSize="@dimen/text.size.small"
                              android:background="@drawable/bg_fab"
                              tools:text="10" />
                              </RelativeLayout>
                              </RelativeLayout>





                              share|improve this answer













                              For this problem solution is android:elevation="7dp". But you are looking for something like this then use bellow code:



                              enter image description here



                              <?xml version="1.0" encoding="utf-8"?>
                              <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                              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"
                              android:layout_width="match_parent"
                              android:layout_height="match_parent">
                              <RelativeLayout
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_alignParentRight="true"
                              android:layout_alignParentBottom="true"
                              android:layout_margin="@dimen/margin.2">
                              <android.support.design.widget.FloatingActionButton
                              android:id="@+id/fab_cart"
                              android:layout_width="wrap_content"
                              android:layout_height="match_parent"
                              android:layout_alignParentRight="true"
                              android:layout_margin="@dimen/margin.2"
                              app:srcCompat="@drawable/ic_add_shopping_cart"
                              app:backgroundTint="@color/colorPrimaryDark" />
                              <TextView
                              android:id="@+id/text_count"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:elevation="7dp"
                              android:gravity="center"
                              android:textColor="@color/white"
                              android:layout_alignParentRight="true"
                              android:textSize="@dimen/text.size.small"
                              android:background="@drawable/bg_fab"
                              tools:text="10" />
                              </RelativeLayout>
                              </RelativeLayout>






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Mar 12 '18 at 7:22









                              Md Imran ChoudhuryMd Imran Choudhury

                              3,00612337




                              3,00612337























                                  0














                                  Give it a Try :



                                  <RelativeLayout
                                  android:layout_width="wrap_content"
                                  android:layout_height="wrap_content"
                                  android:layout_gravity="top|left"
                                  app:layout_anchor="@+id/containerpager"
                                  app:layout_anchorGravity="bottom|right">

                                  <android.support.design.widget.FloatingActionButton
                                  android:id="@+id/fab"
                                  android:layout_width="wrap_content"
                                  android:layout_height="wrap_content"
                                  android:layout_gravity="end|bottom"
                                  android:layout_margin="@dimen/fab_margin"
                                  android:elevation="0dp"
                                  android:visibility="visible"
                                  app:backgroundTint="@color/colorPrimary"
                                  app:borderWidth="0dp"
                                  app:fabSize="normal"
                                  app:srcCompat="@drawable/ic_review_order" />

                                  <TextView
                                  android:layout_width="wrap_content"
                                  android:layout_height="wrap_content"
                                  android:layout_alignParentRight="true"
                                  android:layout_alignParentTop="true"
                                  android:text="5"
                                  android:textColor="@color/white"
                                  android:textSize="22sp"
                                  android:visibility="visible" />
                                  </RelativeLayout>





                                  share|improve this answer




























                                    0














                                    Give it a Try :



                                    <RelativeLayout
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_gravity="top|left"
                                    app:layout_anchor="@+id/containerpager"
                                    app:layout_anchorGravity="bottom|right">

                                    <android.support.design.widget.FloatingActionButton
                                    android:id="@+id/fab"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_gravity="end|bottom"
                                    android:layout_margin="@dimen/fab_margin"
                                    android:elevation="0dp"
                                    android:visibility="visible"
                                    app:backgroundTint="@color/colorPrimary"
                                    app:borderWidth="0dp"
                                    app:fabSize="normal"
                                    app:srcCompat="@drawable/ic_review_order" />

                                    <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_alignParentRight="true"
                                    android:layout_alignParentTop="true"
                                    android:text="5"
                                    android:textColor="@color/white"
                                    android:textSize="22sp"
                                    android:visibility="visible" />
                                    </RelativeLayout>





                                    share|improve this answer


























                                      0












                                      0








                                      0







                                      Give it a Try :



                                      <RelativeLayout
                                      android:layout_width="wrap_content"
                                      android:layout_height="wrap_content"
                                      android:layout_gravity="top|left"
                                      app:layout_anchor="@+id/containerpager"
                                      app:layout_anchorGravity="bottom|right">

                                      <android.support.design.widget.FloatingActionButton
                                      android:id="@+id/fab"
                                      android:layout_width="wrap_content"
                                      android:layout_height="wrap_content"
                                      android:layout_gravity="end|bottom"
                                      android:layout_margin="@dimen/fab_margin"
                                      android:elevation="0dp"
                                      android:visibility="visible"
                                      app:backgroundTint="@color/colorPrimary"
                                      app:borderWidth="0dp"
                                      app:fabSize="normal"
                                      app:srcCompat="@drawable/ic_review_order" />

                                      <TextView
                                      android:layout_width="wrap_content"
                                      android:layout_height="wrap_content"
                                      android:layout_alignParentRight="true"
                                      android:layout_alignParentTop="true"
                                      android:text="5"
                                      android:textColor="@color/white"
                                      android:textSize="22sp"
                                      android:visibility="visible" />
                                      </RelativeLayout>





                                      share|improve this answer













                                      Give it a Try :



                                      <RelativeLayout
                                      android:layout_width="wrap_content"
                                      android:layout_height="wrap_content"
                                      android:layout_gravity="top|left"
                                      app:layout_anchor="@+id/containerpager"
                                      app:layout_anchorGravity="bottom|right">

                                      <android.support.design.widget.FloatingActionButton
                                      android:id="@+id/fab"
                                      android:layout_width="wrap_content"
                                      android:layout_height="wrap_content"
                                      android:layout_gravity="end|bottom"
                                      android:layout_margin="@dimen/fab_margin"
                                      android:elevation="0dp"
                                      android:visibility="visible"
                                      app:backgroundTint="@color/colorPrimary"
                                      app:borderWidth="0dp"
                                      app:fabSize="normal"
                                      app:srcCompat="@drawable/ic_review_order" />

                                      <TextView
                                      android:layout_width="wrap_content"
                                      android:layout_height="wrap_content"
                                      android:layout_alignParentRight="true"
                                      android:layout_alignParentTop="true"
                                      android:text="5"
                                      android:textColor="@color/white"
                                      android:textSize="22sp"
                                      android:visibility="visible" />
                                      </RelativeLayout>






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Oct 28 '17 at 12:26









                                      LMJ-ackLMJ-ack

                                      111




                                      111























                                          -2














                                          try this changes:



                                          <FrameLayout
                                          android:layout_width="wrap_content"
                                          android:layout_height="wrap_content"
                                          android:layout_gravity="end|bottom"
                                          android:id="@+id/frameLayout">

                                          <android.support.design.widget.FloatingActionButton
                                          xmlns:app="http://schemas.android.com/apk/res-auto"
                                          android:id="@+id/listen_button"
                                          android:layout_width="wrap_content"
                                          android:layout_height="match_parent"
                                          android:src="@android:color/transparent"
                                          app:backgroundTint="#e3e3e3" />

                                          <TextView
                                          android:id="@+id/textOne"
                                          android:layout_width="wrap_content"
                                          android:layout_height="wrap_content"
                                          android:text="10"
                                          android:textColor="#FFF"
                                          android:textSize="10sp"
                                          android:textStyle="bold"
                                          android:background="@drawable/badge_circle"/>

                                          </FrameLayout>





                                          share|improve this answer
























                                          • not working on RelativeLayout.

                                            – Md Imran Choudhury
                                            May 25 '17 at 9:21
















                                          -2














                                          try this changes:



                                          <FrameLayout
                                          android:layout_width="wrap_content"
                                          android:layout_height="wrap_content"
                                          android:layout_gravity="end|bottom"
                                          android:id="@+id/frameLayout">

                                          <android.support.design.widget.FloatingActionButton
                                          xmlns:app="http://schemas.android.com/apk/res-auto"
                                          android:id="@+id/listen_button"
                                          android:layout_width="wrap_content"
                                          android:layout_height="match_parent"
                                          android:src="@android:color/transparent"
                                          app:backgroundTint="#e3e3e3" />

                                          <TextView
                                          android:id="@+id/textOne"
                                          android:layout_width="wrap_content"
                                          android:layout_height="wrap_content"
                                          android:text="10"
                                          android:textColor="#FFF"
                                          android:textSize="10sp"
                                          android:textStyle="bold"
                                          android:background="@drawable/badge_circle"/>

                                          </FrameLayout>





                                          share|improve this answer
























                                          • not working on RelativeLayout.

                                            – Md Imran Choudhury
                                            May 25 '17 at 9:21














                                          -2












                                          -2








                                          -2







                                          try this changes:



                                          <FrameLayout
                                          android:layout_width="wrap_content"
                                          android:layout_height="wrap_content"
                                          android:layout_gravity="end|bottom"
                                          android:id="@+id/frameLayout">

                                          <android.support.design.widget.FloatingActionButton
                                          xmlns:app="http://schemas.android.com/apk/res-auto"
                                          android:id="@+id/listen_button"
                                          android:layout_width="wrap_content"
                                          android:layout_height="match_parent"
                                          android:src="@android:color/transparent"
                                          app:backgroundTint="#e3e3e3" />

                                          <TextView
                                          android:id="@+id/textOne"
                                          android:layout_width="wrap_content"
                                          android:layout_height="wrap_content"
                                          android:text="10"
                                          android:textColor="#FFF"
                                          android:textSize="10sp"
                                          android:textStyle="bold"
                                          android:background="@drawable/badge_circle"/>

                                          </FrameLayout>





                                          share|improve this answer













                                          try this changes:



                                          <FrameLayout
                                          android:layout_width="wrap_content"
                                          android:layout_height="wrap_content"
                                          android:layout_gravity="end|bottom"
                                          android:id="@+id/frameLayout">

                                          <android.support.design.widget.FloatingActionButton
                                          xmlns:app="http://schemas.android.com/apk/res-auto"
                                          android:id="@+id/listen_button"
                                          android:layout_width="wrap_content"
                                          android:layout_height="match_parent"
                                          android:src="@android:color/transparent"
                                          app:backgroundTint="#e3e3e3" />

                                          <TextView
                                          android:id="@+id/textOne"
                                          android:layout_width="wrap_content"
                                          android:layout_height="wrap_content"
                                          android:text="10"
                                          android:textColor="#FFF"
                                          android:textSize="10sp"
                                          android:textStyle="bold"
                                          android:background="@drawable/badge_circle"/>

                                          </FrameLayout>






                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Jun 5 '16 at 8:23









                                          mehrdad khosravimehrdad khosravi

                                          2,14292131




                                          2,14292131













                                          • not working on RelativeLayout.

                                            – Md Imran Choudhury
                                            May 25 '17 at 9:21



















                                          • not working on RelativeLayout.

                                            – Md Imran Choudhury
                                            May 25 '17 at 9:21

















                                          not working on RelativeLayout.

                                          – Md Imran Choudhury
                                          May 25 '17 at 9:21





                                          not working on RelativeLayout.

                                          – Md Imran Choudhury
                                          May 25 '17 at 9:21


















                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37639698%2fbadge-count-on-floating-action-button%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          To store a contact into the json file from server.js file using a class in NodeJS

                                          Redirect URL with Chrome Remote Debugging Android Devices

                                          Dieringhausen