• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Custom Notification - Paddings

Manu_29295

Lurker
Hi,

I created a custom notification. However, I like to use the same padding for left- and right-padding that is used for standard notifications. I noticed that this padding can be different depending on the device.

I found the followinf notification style that applies the correct left-right-padding, but it also adds additional stuff that I do not like. Example for the style:

NotificationCompat.Style style = new NotificationCompat.DecoratedCustomViewStyle();
builder.setStyle(style);

So I basically would like to apply the same left/right padding that is applied by the DecoratedCustomViewStyle, but without all that extra stuff.

Does anyone has experience how I can get the correct left-right padding for the notification?

Thanks in advance &
Best regards,
Manuel
 
Try posting a screenshot and some code, that might help us see what you're trying to do better.

Use <code> </code> tags to wrap your code to keep the formatting (just replace < and > with [ and ] for it to work)
 
I create a notification with custom content:

NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "MyNotification");
builder.setContent(rv);
builder.setCustomBigContentView(rv);

See the picture below: The red rectangle shows the padding. If I use a custom notification, my layout will not have this padding applied. Instead I have to take care of this by myself. I want my notification to have the same padding as those standard notification but I dont know where to retrieve this information. Any ideas?


notification-drawer-2x.png
 
Last edited:
I'm really not clear on what the problem is. You should be able to add padding or margins or something like that to whatever layout you're using. What is your layout XML code?
 
Hi Tony,

Thanks for your reply. The problem is, that the left-right-padding can vary depending on the device. So I need to retrieve the padding-value for the specific device.

Example:
On my Samsung S7 the left-right-padding of the notifications are ~20dp. On my Xiaomi device the left-right-padding is 0dp.

Hope this makes my question more clear.

Thank you &
Best regards,
Manuel
 
That would seem to indicate that you need to provide multiple layouts for different screen resolutions and pixel densities, with the padding different for each, if it's really that important to match exactly.

I think at this point I would be questioning if it's that important to get that close of a match, or look at alternative approaches to accomplish the desired result.
 
Back
Top Bottom