Durga Dutt
Durga Dutt

Reputation: 4113

Android Notification Icon

I am giving notification by a background service. In notification i am displaying an image , image dimensions are 15*15. But when image is showed it automatically streches to big size , so it became blur. I haven't specified the image size in my program. Why this is happening

Upvotes: 6

Views: 19929

Answers (3)

weston
weston

Reputation: 54811

The small icons

Guildlines says 24x24, that is for mdpi.

Applying the conversion dp*density/160 you get these pixels resolutions:

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

(The guidelines actually now list these 4 dimensions)

Dynamically sized large icons

If you're creating an image, or resizing an image to fix the large notification image area, you can get the pixel dimensions like so:

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

Upvotes: 8

Pavel Alexeev
Pavel Alexeev

Reputation: 6080

Refer status bar icon guidelines: http://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html

For hdpi status bar icon image should be 38px height (24x38),
mdpi - 16x25
ldpi - 12x19

Upvotes: 10

Octavian Helm
Octavian Helm

Reputation: 39603

That is because when specifying dimensions in Java it is automatically regarded as a pixel value.

You will have to implement a helper method somewhere, best in a helper class, which calculates and returns a density independent pixel value 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 even better actually.

Upvotes: 0

Related Questions