Regarding ConstraintLayout Notification Badge
I have used ConstraintLayout for notification as shown below.
here i used ImageButton and textview
out put:
here i used Button and textview
output :
insted of imageview is used button then it look like this. can any help me to solve this in constraintLayout.
ex :
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.
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.
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.
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.
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.
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.
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"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With