【发布时间】:2019-12-27 10:01:37
【问题描述】:
我正在使用折叠和展开视图制作持久通知。但是我折叠的视图在底部占用了额外的空间。这不是我想出来的布局问题。
最初,我为展开视图和折叠视图创建了单独的布局,但我意识到通知标题需要默认设计,因此我删除了折叠视图布局。
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);
请在下面找到我用于扩展通知视图的布局文件。我不为折叠视图使用任何布局。我想要扩展通知中的标题、描述和两个按钮。从两个按钮点击,我直接打开活动。
删除ExpandedViews.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>
【问题讨论】:
-
使用 uiautomatorviewer 检查 UI 层次结构并查看它为您的通知膨胀的附加视图。
-
您好,能否请您同时粘贴您的
ic_fix_icon和remoteExpandedViews? -
@ravi 请检查。
标签: android android-layout push-notification notifications