1. Download our Official Android App: Forums for Android!

Custom Notification - Paddings

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

  1. Manu_29295

    Manu_29295 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Aug 7, 2019

    Aug 7, 2019
    4
    0
    5
    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
     

    Advertisement

  2. Manu_29295

    Manu_29295 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Aug 7, 2019

    Aug 7, 2019
    4
    0
    5
  3. 23tony

    23tony Well-Known Member
    Rank:
     #137
    Points:
    83
    Posts:
    186
    Joined:
    Mar 26, 2019

    Mar 26, 2019
    186
    68
    83
    Programmer
    Raleigh, NC
    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
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Aug 7, 2019

    Aug 7, 2019
    4
    0
    5
    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 at 3:12 PM
    Last edited: Aug 13, 2019 at 3:21 PM
  5. 23tony

    23tony Well-Known Member
    Rank:
     #137
    Points:
    83
    Posts:
    186
    Joined:
    Mar 26, 2019

    Mar 26, 2019
    186
    68
    83
    Programmer
    Raleigh, NC
    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
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Aug 7, 2019

    Aug 7, 2019
    4
    0
    5
    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
    Rank:
     #137
    Points:
    83
    Posts:
    186
    Joined:
    Mar 26, 2019

    Mar 26, 2019
    186
    68
    83
    Programmer
    Raleigh, NC
    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.
     

Share This Page

Loading...