Ответ 1
Добавить RemoteViews
в уведомлении. Вот образец:
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>
проверить эту статью есть больше стиль avaialbe
Отредактировано:
NotificationCompat.Builder - это самый простой способ создания уведомлений на всех версиях Android. Вы даже можете использовать функции, доступные в Android 4.1. Если ваше приложение работает на устройствах с Android> = 4.1, будут использоваться новые функции, если оно работает на Android <4.1, уведомление будет простым старым уведомлением.
для <11 API используйте http://www.framentos.com/en/android-tutorial/2012/02/20/how-to-create-a-custom-notification-on-android/