繁体   English   中英

Android通知大图标,有没有办法删除右下方的小图标?

[英]Android notification large icon, is there a way to remove the smaller icon on the bottom right?

我有一个显示大图的通知。

有没有办法从此视图中删除蜂窝和上方设备中的较小图标?

显然仍然保留顶部状态栏的小图标

在此输入图像描述

   NotificationCompat.Builder builder = new NotificationCompat.Builder(context)


            // Set required fields, including the small icon, the
            // notification title, and text.
            .setSmallIcon(R.drawable.ic_notify_status_new)
            .setContentTitle(title)
            .setContentText(text)


            // All fields below this line are optional.

            // Use a default priority (recognized on devices running Android
            // 4.1 or later)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)

            // Provide a large icon, shown with the notification in the
            // notification drawer on devices running Android 3.0 or later.
            .setLargeIcon(picture)

            .setContentIntent(
                    PendingIntent.getActivity(
                            context,
                            0,
                            notiIntent,
                            PendingIntent.FLAG_UPDATE_CURRENT)
            );


    builder = getNotiSettings(builder);
    notify(context, builder.build());

生成通知后添加此代码。

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int smallIconViewId = getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());

        if (smallIconViewId != 0) {
            if (notif.contentIntent != null)
                notif.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE);

            if (notif.headsUpContentView != null)
                notif.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);

            if (notif.bigContentView != null)
                notif.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
        }
    }

其中“notif”是您建立的通知,

只有一种方法:使用自定义布局

您的问题很可能是NotificationCompat 4.1 SetSmallIcon和SetLargeIcon的副本

仅将setSmallIcon用于您的图标。 如果没有指定第二个,它也将用于largeIcon(只要确保它足够大以适应两者)。

确保它在pre-lolipop,lolipop及以上看起来不错。 例如,这里我只为pre-lolipop设备设置应用程序图标,其中lolipop及以上版本的smallIcon与smallIcon相同,smallIcon也相同。

int currentApiVersion = android.os.Build.VERSION.SDK_INT;
if (currentApiVersion >= Build.VERSION_CODES.LOLLIPOP) {
    notificationBuilder
        .setSmallIcon(smallIcon)
        .setLargeIcon(appIconDrawable)
} else {
    notificationBuilder.setSmallIcon(appIconDrawable);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM