Ответ 1
Да, все это делается с помощью пользовательского RemoteViews
. Вы увидите в документах Notification
поле для bigContentView
вместе с contentView
.
Я пытаюсь создать уведомление, которое очень похоже на то, что использует приложение "Play Music" из Google.
Несколько вопросов, которые, надеюсь, кто-то может ответить.
Да, все это делается с помощью пользовательского RemoteViews
. Вы увидите в документах Notification
поле для bigContentView
вместе с contentView
.
Я знаю, что мне очень поздно отвечать, но это касается новых людей, которые опробовали уведомления в средствах массовой информации.
Не нужно использовать RemoteViews
. Теперь мы можем просто использовать NotificationCompat.MediaStyle()
. Он отлично работает по мере необходимости и обеспечивает единообразие в потреблении потребления Media
.
При использовании уведомлений MediaStyle не будет кнопки X для версий > Lollipop. Скорее мы уведомляем об этом уведомление в состоянии Paused. В таких случаях процесс, который следует соблюдать, показан в этой ссылке.
Уведомление MediaStyle имеет setShowActionsInCompactView()
, чтобы определить, какие все действия должны отображаться в компактном режиме. Ниже приведен фрагмент:
notificationBuilder.addAction(R.drawable.notification_play, "Play",
createPlayIntent());
notificationBuilder.addAction(R.drawable.notification_next, "Next", createNextIntent())
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setStyle(new NotificationCompat.MediaStyle()
.setShowCancelButton(true)
.setCancelButtonIntent(createPlayIntent())
.setShowActionsInCompactView(0, 1, 2);
Это должно помочь вам при настройке всего медиа-уведомления по мере необходимости. Счастливое кодирование!
<ImageView
android:id="@+id/thumbnail"
android:layout_width="@dimen/notification_expanded_height"
android:layout_height="@dimen/notification_expanded_height"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="@drawable/notification"
android:scaleType="fitXY" />
<LinearLayout
android:id="@+id/buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/thumbnail"
android:divider="?android:listDivider"
android:dividerPadding="12.0dip"
android:gravity="center_vertical"
android:orientation="horizontal"
android:showDividers="middle" >
<ImageButton
android:id="@+id/prev"
android:layout_width="0.0dip"
android:layout_height="@dimen/play_controls_notification"
android:layout_weight="1.0"
android:background="?android:selectableItemBackground"
android:padding="10.0dip"
android:scaleType="fitCenter"
android:src="@drawable/btn_playback_rew_jb_dark" />
<ImageButton
android:id="@+id/playpause"
android:layout_width="0.0dip"
android:layout_height="@dimen/play_controls_notification"
android:layout_weight="1.0"
android:background="?android:selectableItemBackground"
android:padding="10.0dip"
android:scaleType="fitCenter"
android:src="@drawable/btn_playback_pause_jb_dark" />
<ImageButton
android:id="@+id/next"
android:layout_width="0.0dip"
android:layout_height="@dimen/play_controls_notification"
android:layout_weight="1.0"
android:background="?android:selectableItemBackground"
android:padding="10.0dip"
android:scaleType="fitCenter"
android:src="@drawable/btn_playback_ff_jb_dark" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="1.0px"
android:layout_above="@id/buttons"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/thumbnail"
android:background="?android:dividerHorizontal" />
<ImageButton
android:id="@+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="?android:selectableItemBackground"
android:padding="8.0dip"
android:src="@drawable/ic_close_notification_holo_dark" />
<LinearLayout
android:id="@+id/textarea"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="center_vertical"
android:layout_toLeftOf="@id/stop"
android:layout_toRightOf="@id/thumbnail"
android:orientation="vertical"
android:paddingLeft="@dimen/notification_padding"
android:paddingTop="8.0dip" >
<TextView
android:id="@+id/trackname"
style="@android:style/TextAppearance.StatusBar.EventContent.Title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:focusable="true"
android:singleLine="true" />
<Chronometer
android:id="@+id/duration"
style="@android:style/TextAppearance.StatusBar.EventContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:ellipsize="marquee"
android:layout_marginTop="6dp"
android:fadingEdge="horizontal"
android:maxLines="1" />
</LinearLayout>
2. notification.bigContentView Assigninment RemoteView