Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 573
R KiranKumar Avatar asked Apr 16 '17 05:04

R KiranKumar


People also ask

How do I show badge on app icon Android?

If you want to change badge with number, you can be changed in NOTIFICATION SETTING on the notification panel or Settings > Notifications > App icon badges > Select Show with number.

What is an Android studio user badge?

Starting with 8.0 (API level 26), notification badges (also known as notification dots) appear on a launcher icon when the associated app has an active notification. Users can long-press on the app icon to reveal the notifications (alongside any app shortcuts), as shown in figure 1.

Is ConstraintLayout faster than LinearLayout?

More complex layout but results are the same, flat Constraint Layout is slower than nested Linear Layout. I want to pay attention to 2 more things which are more subjective. Creating Constraint Layout takes more time than other layouts. Also introducing changes in existing Constraint Layout is much more time-consuming.

Why do we use ConstraintLayout in Android?

A ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way. Note: ConstraintLayout is available as a support library that you can use on Android systems starting with API level 9 (Gingerbread). As such, we are planning on enriching its API and capabilities over time.


2 Answers

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.

like image 67
Oğuzhan Döngül Avatar answered Oct 04 '22 15:10

Oğuzhan Döngül


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"/>
like image 39
S Haque Avatar answered Oct 04 '22 15:10

S Haque