1

Currently in Android, the notification action button appears by default as right aligned to the screen. I am showing two action buttons in my app and they're shown right aligned by default.

Can we alter the position of the action buttons as I want them center aligned?

6
  • You can create your own Custom View for the Notification. Then you can set the buttons wherever you want.
    – Rachit
    Feb 7, 2017 at 6:31
  • But i want big picture style and expandable behaviour also. Is it feasible?
    – PKhurana
    Feb 7, 2017 at 6:33
  • You might want to take a look at this link codeversed.com/expandable-notifications-android
    – Rachit
    Feb 7, 2017 at 6:34
  • All you would need to do is set the notification.bigContentView as your custom RemoteView.
    – Rachit
    Feb 7, 2017 at 6:38
  • Gone through the link.I know how can i set custom layout notification but i suspect that i will get same kind of behaviour which android has like after expand only action button and big picture should appear. what u say
    – PKhurana
    Feb 7, 2017 at 6:40

1 Answer 1

4

You won't be able to pick how the default actions are displayed (besides customizing the text and icons) but you can instead implement a completely custom view for your Notification.

See setCustomView() which lets you pass a RemoteViews object that can be inflated from your own layout. You can define any type of buttons that you want and align them in your own desired way. You will just have to set a click listener on the specific views for those buttons within your RemoteViews to launch your PendingIntent when the buttons are clicked.

2
  • will those button will come only after expanding the notification? I need this behaviour of android notification also
    – PKhurana
    Feb 7, 2017 at 6:42
  • You should be able to define a layout for before the notification expands with setContent(RemoteViews) and if you want to also set the expanded notification you can use setCustomBigContentView(RemoteViews) see here for an example: laurivan.com/android-notifications-with-custom-layout Feb 7, 2017 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.