我正在通过折叠和展开视图发出持久通知。但是我崩溃的视图在底部占用了额外的空间。我发现这不是布局问题。
最初,我为展开和折叠视图创建了一个单独的布局,但是我意识到我需要为通知标头使用默认设计,因此我删除了折叠视图布局。
mBuilder.setSmallIcon(R.drawable.ic_fix_icon)
.setAutoCancel(false)
.setOngoing(true)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomBigContentView(remoteExpandedViews)
.setPriority(Notification.PRIORITY_MAX)
.setChannelId(NOTIFICATION_CHANNEL_ID);
请在布局文件下方找到我已用于扩展的通知视图的布局文件。我不对折叠视图使用任何布局。我要在扩展通知中添加标题,描述和两个按钮。从两个按钮单击,我直接打开活动。
removeExpandedViews.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_margin="0dp"
android:padding="0dp"
android:background="@android:color/transparent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/custome_expanded_notification_relativelayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/custome_expanded_notification_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextAppearance.Compat.Notification.Info"
android:text="Today's task"
android:fontFamily="@font/robotomedium"
android:ellipsize="end"
android:textColor="@color/gray"
android:textSize="12sp"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_alignParentLeft="true"/>
<ImageView
android:id="@+id/custome_expanded_notification_next_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_next_icon"
android:tint="@color/black"
android:visibility="gone"
android:padding="10dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"/>
<TextView
android:id="@+id/custome_expanded_notification_task"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No task for today !"
android:ellipsize="end"
android:textSize="14sp"
android:layout_marginTop="2dp"
android:textColor="@color/black"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="@+id/custome_expanded_notification_next_icon"
style="@style/TextAppearance.Compat.Notification.Title"
android:fontFamily="@font/robotomedium"
android:layout_below="@+id/custome_expanded_notification_title"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/custome_expanded_notification_relativelayout1"
android:padding="0dp"
android:layout_marginLeft="5dp">
<TextView
android:id="@+id/custome_expanded_notification_add_task"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Task"
android:padding="0dp"
android:textStyle="bold"
android:textAllCaps="true"
android:textColor="@color/textColorTitle"
android:fontFamily="@font/robotobold"
android:textSize="11dp"
android:layout_marginTop="10dp"
android:gravity="center"/>
<TextView
android:id="@+id/custome_expanded_notification_setting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Setting"
android:textStyle="bold"
android:padding="0dp"
android:textAllCaps="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/custome_expanded_notification_add_task"
android:textColor="@color/textColorTitle"
android:fontFamily="@font/robotobold"
android:textSize="11dp"
android:layout_marginTop="10dp"
android:gravity="center"/>
</RelativeLayout>
</RelativeLayout>
答案 0 :(得分:1)
使用它,肯定会起作用。
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
chan.setLightColor(Color.BLUE);
chan.setImportance(NotificationManager.IMPORTANCE_UNSPECIFIED);
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
答案 1 :(得分:0)