如何在自定义通知中从左侧删除图标?

时间:2019-06-03 13:54:33

标签: android android-layout android-notifications android-notification-bar

您好,我正在尝试创建自定义通知,但是addAction图标smallIcon和largeicon不能正确显示,然后我想创建一个不带图标的自定义通知,并将其放在布局中。

这可能吗?

我的代码:

    public static NotificationCompat.Builder createNotification(Context context, String message){
        String packageName = context.getPackageName();

        RemoteViews notificationLayout = new RemoteViews(packageName, R.layout.notification);
        RemoteViews notificationLayoutExpanded = new RemoteViews(packageName, R.layout.notification_expanded);

        NotificationCompat.Builder builder =
                new NotificationCompat.Builder(context, CHANNEL_ID)
                        .setSmallIcon(R.drawable.ic_logo_solo)
                        .setStyle(new android.support.v4.app.NotificationCompat.DecoratedCustomViewStyle())
                        .setCustomBigContentView(notificationLayoutExpanded)
                        .setCustomContentView(notificationLayout);

        return builder;
    }

...
NotificationCompat.Builder builder = AssistanceNotification.createNotification(this, message);
        Notification notification = builder.addAction(R.drawable.ic_gps, getString(R.string.assits), intentAssist)
                .addAction(R.drawable.ic_gps, getString(R.string.omit), intentOmit)
                .setTimeoutAfter(TIMEOUT) // works only for api > 26
                .build();

        AssistanceNotification.notify(this, notification);
...

通知的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="64dp" >
<ImageView
    app:srcCompat="@drawable/ic_logo_alert"
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_marginRight="10dp" />
<TextView
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:text="Collpasepd notification"
    style="@style/TextAppearance.Compat.Notification.Title"/>
<TextView
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:text="Hello from colapse notification"
    style="@style/TextAppearance.Compat.Notification.Info"/>

0 个答案:

没有答案