R KiranKumar
R KiranKumar

Reputation: 835

ConstraintLayout Notification Badge

Regarding ConstraintLayout Notification Badge

I have used ConstraintLayout for notification as shown below.

here i used ImageButton and textview enter image description here

out put:

enter image description here

here i used Button and textview

enter image description here

output :

enter image description here

insted of imageview is used button then it look like this. can any help me to solve this in constraintLayout.

ex : enter image description here

when i tryed with button it displaying like this .

one more new thing i got to know if you are using FrameLayout or RelativeLayout display badge is working fine for both Button , ImageView or ImageButtom.

But on long-press or click of Button Notification badge is going back , in Imageview and imagebutton it working fine.

Upvotes: 10

Views: 2375

Answers (3)

R KiranKumar
R KiranKumar

Reputation: 835

Final i got the solution for the above question

1 : for Button android:elevation will not effect beacuse internal it has elevation.

instead of elevation use android:stateListAnimator="@null"

2 : for other then button elevation will work

Upvotes: 0

S Haque
S Haque

Reputation: 7281

Use this style="?android:attr/borderlessButtonStyle" in the Button xml

<Button
        style="?android:attr/borderlessButtonStyle"
        android:background="@mipmap/ic_launcher"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

Upvotes: 2

This happens, because Button has its own elevation.

Higher elevation, gets views to the front.

Try adding higher elevation to your Badge like below.

android:elevation="10dp"

And, you don't want to scale your Image, you must use ImageView or ImageButton.

Upvotes: 3

Related Questions