2 回答

TA貢獻(xiàn)1995條經(jīng)驗(yàn) 獲得超2個(gè)贊
添加RemoteViews通知。這是一個(gè)示例:
var remoteViews = new RemoteViews(getPackageName(), R.layout.widget);
var mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContent(remoteViews);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, test.class);
// The stack builder object will contain an artificial back stack for
// the started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(test.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.button1, resultPendingIntent);
var notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
notificationManager.notify(100, mBuilder.build());
widget.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="DJ notification"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Close Me" />
</LinearLayout>
檢查這篇文章還有更多的樣式可供選擇
Android開(kāi)發(fā)人員
編輯:
NotificationCompat.Builder是在所有Android版本上創(chuàng)建通知的最簡(jiǎn)單方法。您甚至可以使用Android 4.1可用的功能。如果您的應(yīng)用程序在Android> = 4.1的設(shè)備上運(yùn)行,則將使用新功能;如果在Android <4.1的設(shè)備上運(yùn)行,則通知將是簡(jiǎn)單的舊通知。
對(duì)于<11 API,請(qǐng)使用http://www.framentos.com/zh-CN/android-tutorial/2012/02/20/how-to-create-a-custom-notification-on-android/

TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊
從Android 4.1開(kāi)始,可以使用擴(kuò)展的通知來(lái)處理這些情況。如果您使用Notification.Builder或NotificationCompat.Builder,則可以使用或其他樣式之一為展開(kāi)的通知設(shè)置普通樣式和Builder單獨(dú)樣式,然后將兩者連接起來(lái)。BuilderNotificationCompat.InboxStyle
- 2 回答
- 0 關(guān)注
- 506 瀏覽
添加回答
舉報(bào)