Android Notification Icon

I am notifying the background service. In the notification, I show the image, the image size is 15 * 15. But when the image is displayed, it is automatically stretched to a large size, so it becomes blurry. I did not specify the image size in my program. Why is this happening

+6
source share
3 answers

This is because when you specify dimensions in Java, it is automatically treated as a pixel value.

You will need to implement a helper method somewhere, best of all in a helper class that calculates and returns a value independent of pixel density based on the provided pixel value.

The equation is px = dip * (density / 160) , from which we get that dip = px / (density/160) .

This answer here is actually even better.

0
source

Please note: http://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html

The hdpi status icon should have 38px height (24x38),
mdpi - 16x25
ldpi - 12x19

+10
source

Small icons

Guildlines says 24x24, i.e. for mdpi.

Using the dp*density/160 transform, you get the resolution of these pixels:

ldpi 18x18
mdpi 24x24
hdpi 36x36
xhdpi 48x48

(These 4 dimensions are now listed in these manuals)

Large size icons with dynamic size

If you create an image or resize the image to fix a large area of ​​the notification image, you can get the pixel sizes as follows:

 int width = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_width); int height = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); 

See https://developer.android.com/reference/android/R.dimen.html#notification_large_icon_height

+8
source

Source: https://habr.com/ru/post/886778/


All Articles