Badge count on Floating action button

前端 未结 8 1867
一整个雨季
一整个雨季 2021-01-05 02:26

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



        
相关标签:
8条回答
  • 2021-01-05 02:53

    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>
    
    0 讨论(0)
  • 2021-01-05 02:54

    you might wanna try this

    <FrameLayout
        android:layout_gravity="bottom|end"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    
        <com.nex3z.notificationbadge.NotificationBadge
            android:id="@+id/badge"
            android:layout_width="28dp"
            android:layout_height="28dp"
            android:layout_gravity="right|top"
            android:elevation="7dp"
            app:nbMaxTextLength="2" />
    
    
        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginRight="15dp"
            android:src="@drawable/ic_shopping_cart_black_24dp"
            app:backgroundTint="@color/colorprice" />
    </FrameLayout>    
    
    0 讨论(0)
提交回复
热议问题