Is there a template for Honeycomb-style custom notifications? - android

I'm trying to create a custom notification layout that looks just like a 3.0 notification, with a couple of extra things sprinkled in. More importantly, I also want to derive a Jelly Bean expanded notification on top of that.
I'd like the notification to have the same layout as a stock notification so it fits in nicely, i.e. like this (bottom image):
However, I cannot find any information about the proper dimensions and styles - what size do I need to use for the image on the left? What style for each text? What padding?
Ideally, I'd love to use something like android.R.listPreferredItemHeight for the height of the layout and the dimensions of the image, but I can't find anything that pertains to notifications.

You can use the Notification.Builder class which provides a convenient way to set the various fields of a Notification and generate content views using the platform's notification layout template.
See: http://developer.android.com/reference/android/app/Notification.Builder.html
If you need to be compatible with versions prior to API level 11 then take a look at the NotificationCompat.Builder from the support library.

Related

Change notification style

does anyone know how to define style like mediastyle for notifications in android. I want to use different background color for notification that appear on devices who has android version 5.0 or above. I want to use same color, but I want to use different height of notification, and I don't want a buttons in notification. Currently I use custom view for notification that has same background color like medaistyle notification, but custom view appears only on devices that has version of android lower then 5.0 . Can anyone help please
Thank you very much

Making custom notifications match default style

I'm struggling with creating a custom notification whose expanded view is defined by a RemoteView using a bigContentView.
I'd like for this notification to look exactly like a default notification however I'm having issues achieving this across all platforms.
I can pull the font size and color of the title and description using #android:style/TextAppearance.StatusBar.EventContent.Title however I can't seem to find a way to determine what positioning to use for those titles and descriptions (margins, padding).
I also can't seem to determine what icon size or background to use for the icon. For example on some devices, there is a light blue background that appears behind the notification icon, but on Samsungs this doesn't seem to be the case.

Getting default icon background with custom status bar notifications

I'm currently creating a custom status bar notification to notify the user of progress through an event. I have the custom notification working fine, but having a progress bar requires that I pass my own set of RemoteViews to the notification through the contentView field.
This is fine, except that I want to be able to base this layout off the default one. I am targeting API 10, and so it must work with both Gingerbread and ICS. Gingerbread is fine, as I can just put an icon on the left of the layout and the notification fits in with other default ones. In ICS however, the notification icons all have the striped square on the left that contains the icon (it effectively forms a UI "handle" to help indicate that the notification can be swiped to dismiss it).
Does anyone know how I can either get the default layout in code, and then edit it (this is hard with remoteViews), or somehow get access to default layout view (probably during runtime), then copy it, and substitute the notification text for my progress bar?
I have seen examples where people have created a notification and cloned the layout, but to do anything useful with that you have to know quite a lot about the layout. I would rather get the layout files from the android versions you are interested in. Here you have the JB one, you should not have any problems finding the others.
If the only reason you want a custom layout is to get a progress bar, you could look at
NotificationCompat.Builder.setProgress(). It'll be easier than playing with custom notification layouts. If you do decide to use custom layouts, they changed only slightly between API v14 and API v17, and I have no idea what they're like for Honeycomb but they're unlikely to be much different. What that means is that you should be able to use one custom notification layout in a layout-v11 folder, and one in your default layout folder, and you'll catch most cases (except for the icon background from Honeycomb upwards, I haven't gotten that part working in my own custom notifications yet) and only have to maintain two different layouts. See the answer above for the location of the default layout; note that it's called status_bar_latest_event_content.xml in earlier versions of Android.
Since setProgress() is available from Honeycomb upwards at least, and it looks like it works on earlier versions too (the docs don't say otherwise), then you should probably use that if you don't have any other custom requirements.

Where can I get a Notification item layout? Something like android.R.layout.?

As you can see in Android and OEM customisation, the items in Status Bar or Notification bar have different layouts.
The notification also differs depending on the Theme/Rom you installed.
Here is an example with Vanilla/Touchwizz/MIUI:
or or
What I would like to get is the layout, so I can include it in my activity and preview a notification inside my application.
I guess there is something similar to the android.R.layout.simple_list_item_1 for listview for instance.
Thank a lot for any help or any clue.
The layout for notification is located in separate SystemUI package: status_bar_latest_event (as of Android 2.3). This is not directly accessible from application. And if you could extract the layout, it wouldn't help you, as it uses custom com.android.systemui.statusbar.LatestItemView view. So you'd need to load that class into your process using PathClassLoader.
So theoretically this might be possible, but it's going to be tricky.

Size of custom view for android notification

I want to change default android notification view. Can I make height of Custom Expanded View more than 3 lines of text?
Check this article on how to make custom notifications using your own layout. If this helps you already: good. If not: The RemoteView also offers options to create custom notifications, so it might help you. Alternatively you could create multiple notifications if the number of lines is really limited (which I am not sure of).

Categories

Resources