2012-05-09 11 views
5

...これはAndroidの通知(RemoteView)レイアウトですか?私のHTCの携帯電話通知のRemoteViewは、下の画像のように見えるで

enter image description here

私は中の通知を同じレイアウト(画像、太字や小さなテキスト)を使用したいのですが、私のアプリがありますが、在庫Androidのレイアウトかどうかはわかりません。私は自分のレイアウトを作成しましたが、それは全く同じではなく、可能ならば「標準」に固執したいと思います。

私はandroid.R.layout.の入力を試してみましたが、どのような提案があったのかを見てみましたが、通知レイアウトを示唆する名前は表示されません。

Android搭載のレイアウトですか?もしそうなら、どのように私はそれにアクセスするのですか?

答えて

5

標準のAndroid通知レイアウトであり、独自のカスタムレイアウトを作成する必要はありません。既存の通知APIを使用して、ドロウアブル、タイトル、テキストを設定するだけです。

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

と同じ:以下は、互換性ライブラリからNotificationCompat.Builderを使用して、一例であり、

関連する問題