1. Are you ready for the Galaxy S20? Here is everything we know so far!

Custom Notification - Paddings

Discussion in 'Android Development' started by Manu_29295, Aug 7, 2019.

  1. Manu_29295

    Manu_29295 Lurker
    Thread Starter

    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
     


  2. Manu_29295

    Manu_29295 Lurker
    Thread Starter

  3. 23tony

    23tony Well-Known Member

    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)
     
    mikedt likes this.
  4. Manu_29295

    Manu_29295 Lurker
    Thread Starter

    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?


    [​IMG]
     
    #4 Manu_29295, Aug 13, 2019
    Last edited: Aug 13, 2019
  5. 23tony

    23tony Well-Known Member

    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?
     
  6. Manu_29295

    Manu_29295 Lurker
    Thread Starter

    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
     
  7. 23tony

    23tony Well-Known Member

    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.
     
Loading...
Similar Threads - Custom Notification Paddings
  1. mad_jacket
    Replies:
    1
    Views:
    828
  2. LRHG
    Replies:
    0
    Views:
    431
  3. SouthCountryMom
    Replies:
    1
    Views:
    447
  4. Android News
    Replies:
    0
    Views:
    447
  5. Neil Dexter
    Replies:
    10
    Views:
    1,104
  6. RazR2019
    Replies:
    0
    Views:
    563
  7. MikeyMikey123
    Replies:
    4
    Views:
    444
  8. sbk_james
    Replies:
    7
    Views:
    3,413
  9. Alex Ethridge
    Replies:
    4
    Views:
    5,946
  10. dabaterick
    Replies:
    0
    Views:
    402

Share This Page

Loading...