2012-05-09 10 views
5

En mi teléfono HTC el RemoteView para las notificaciones se parece a la imagen de abajo ...¿Es esto un diseño stock de notificación de Android (RemoteView)?

enter image description here

me gustaría utilizar el mismo diseño (imagen, texto en negrita y el texto pequeño) para una notificación en mi aplicación pero no puedo resolver si es un diseño de stock de Android o no. He creado mi propio diseño pero no es lo mismo y me gustaría mantener el 'estándar' si es posible.

Usando eclipse Intenté escribir en android.R.layout. para ver cuáles eran las sugerencias, pero no puedo ver ninguna con un nombre que sugiera un diseño de notificación.

¿Es un diseño común de Android? Si es así, ¿cómo puedo acceder?

Respuesta

5

Es el diseño de notificaciones de Android estándar y no necesita crear su propio diseño personalizado. Simplemente use la API de notificación existente para establecer drawable, title y text. A continuación se muestra un ejemplo, el uso de la biblioteca de compatibilidad NotificationCompat.Builder:

Intent notificationIntent = new Intent(this, ActivityHome.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 
builder.setContentIntent(pendingIntent) 
     .setWhen(System.currentTimeMillis()) 
     .setTicker(getText(R.string.notification_ticker)) 
     .setSmallIcon(R.drawable.notification_icon) 
     .setContentTitle(getText(R.string.notification_title)) 
     .setContentText(getText(R.string.notification_text)); 

mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification()); 

Y lo mismo usando Notification clase:

Notification notification = new Notification(R.drawable.notification_icon, getText(R.string.notification_ticker), System.currentTimeMillis()); 

Intent notificationIntent = new Intent(this, ActivityHome.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); 

notification.setLatestEventInfo(this, getString(R.string.notification_title), getText(R.string.notification_text), pendingIntent); 

mNotificationManager.notify(NOTIFICATION_ID, builder.getNotification()); 
Cuestiones relacionadas