我想创建一个这样的通知
我正在使用RemoteViews,这是我的 custom_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#524E4D">
<ImageView
android:id="@+id/img_noti_song_cover"
android:layout_width="150dp"
android:layout_height="350dp"
android:background="#f441"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/tv_noti_song_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:maxLines="1"
android:layout_marginTop="15dp"
android:text="Hello World"
android:layout_toEndOf="@id/img_noti_song_cover"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff"
android:layout_marginBottom="5dp"/>
<TextView
android:id="@+id/tv_noti_artist_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_noti_song_name"
android:paddingStart="10dp"
android:layout_toEndOf="@+id/img_noti_song_cover"
android:ellipsize="end"
android:maxLines="1"
android:singleLine="true"
android:text="fdsgsfgdfhdf"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#DDD7D5" />
<FrameLayout
android:id="@+id/horizontal_line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ffffff"
android:layout_toEndOf="@id/img_noti_song_cover"
android:layout_below="@id/tv_noti_artist_name"
android:layout_marginTop="15dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/horizontal_line"
android:layout_toEndOf="@id/img_noti_song_cover"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:gravity="center">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1"/>
<ImageView
android:id="@+id/ic_noti_previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_notification_previous"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1"/>
<ImageView
android:id="@+id/ic_noti_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_notification_play"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1"/>
<ImageView
android:id="@+id/ic_noti_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_notification_next"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1"/>
</LinearLayout>
</RelativeLayout>
显示通知的代码
MyNotification.java
//create song playback notification
private void createSongPlaybackNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.playback_channel_id))
.setCustomBigContentView(getRemoteView())
.setContentTitle("SongPlayback Notification")
.setSmallIcon(android.R.drawable.arrow_up_float)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_playback_notification_icon))
.setContentText("this is content text")
.setSubText("sub text")
.setOngoing(true);
playbackNotification = builder.build();
}
//create remote view
private RemoteViews getRemoteView() {
songPlaybackRemoteViews = new RemoteViews(getPackageName(), R.layout.player_notification);
updatePlaybackNotificationUI(songPlaybackRemoteViews);
Intent actionPlaybackIntent = new Intent(ACTION_PLAYBACK);
Intent actionNextIntent = new Intent(ACTION_PLAY_NEXT_SONG);
Intent actionPreviousIntent = new Intent(ACTION_PLAY_PREVIOUS_SONG);
PendingIntent playbackPendingIntent = PendingIntent.getBroadcast(context, 0, actionPlaybackIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent playNextPendingIntent = PendingIntent.getBroadcast(context, 0, actionNextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent playPreviousPendingIntent = PendingIntent.getBroadcast(context, 0, actionPreviousIntent, PendingIntent.FLAG_UPDATE_CURRENT);
songPlaybackRemoteViews.setOnClickPendingIntent(R.id.ic_noti_play, playbackPendingIntent);
songPlaybackRemoteViews.setOnClickPendingIntent(R.id.ic_noti_next, playNextPendingIntent);
songPlaybackRemoteViews.setOnClickPendingIntent(R.id.ic_noti_previous, playPreviousPendingIntent);
return songPlaybackRemoteViews;
}
当我运行应用程序时,它显示的不是我想要的
它被裁剪了一半,就像通常的系统通知的标准高度一样。我已经搜索了许多线程来找到解决方案,但仍然发现任何有用的东西。我也尝试了 setContent(remoteViews)和 setBigCustomContentView(remoteViews),但仍然是相同的