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?

Pang
  • 9,564
  • 146
  • 81
  • 122
PKhurana
  • 35
  • 1
  • 6
  • You can create your own Custom View for the Notification. Then you can set the buttons wherever you want. – Rachit Feb 07 '17 at 06:31
  • But i want big picture style and expandable behaviour also. Is it feasible? – PKhurana Feb 07 '17 at 06:33
  • You might want to take a look at this link http://codeversed.com/expandable-notifications-android/ – Rachit Feb 07 '17 at 06:34
  • All you would need to do is set the notification.bigContentView as your custom RemoteView. – Rachit Feb 07 '17 at 06: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 07 '17 at 06:40
  • I think it'll work. Just set the customView under notification.bigContentView. – Rachit Feb 07 '17 at 06:59

1 Answers1

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.

mattgmg1990
  • 5,576
  • 4
  • 21
  • 26
  • will those button will come only after expanding the notification? I need this behaviour of android notification also – PKhurana Feb 07 '17 at 06: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: https://www.laurivan.com/android-notifications-with-custom-layout/ – mattgmg1990 Feb 07 '17 at 06:50