2012-05-09 72 views
5

在我的HTC手機通知的遠程視窗看起來像下面的圖片...這是一個股票Android通知(RemoteView)佈局?

enter image description here

我想使用相同的佈局(圖像,大膽的文字和小文),用於在通知我應用程序,但我不能解決它是否是一個股票Android佈局或不。我已經創建了自己的佈局,但它不完全相同,如果可能的話,我想堅持'標準'。

使用eclipse我嘗試在android.R.layout.中輸入以查看這些建議是什麼,但我無法看到任何帶有建議通知佈局的名稱。

它是一個股票Android佈局?如果是這樣,我該如何訪問它?

回答

5

這是標準的Android通知佈局,您不需要創建自己的自定義佈局。只需使用現有的通知API來設置可繪製,標題和文本。下面是一個例子,使用從NotificationCompat.Builder兼容性庫:使用Notification

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()); 

而同樣的:

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());