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

社会主义新天地 提交于 2019-12-04 01:18:43

Add this code after you build the notification.

   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);
        }
    }

where "notif" is your built notification,

Jean Y.C. Yang

There is only one way: Use your custom layout

Your question is probable a duplicate of NotificationCompat 4.1 SetSmallIcon and SetLargeIcon

Use only setSmallIcon for Your icon. It will be also used for largeIcon if second wasn't specified (just make sure it is big enough to fit both).

Make sure that it looks good on pre-lolipop, lolipop and above. For example here I do set application icon only for pre-lolipop devices, where lolipop and above are getting different smallIcon and same largeIcon as smallIcon.

int currentApiVersion = android.os.Build.VERSION.SDK_INT;
if (currentApiVersion >= Build.VERSION_CODES.LOLLIPOP) {
    notificationBuilder
        .setSmallIcon(smallIcon)
        .setLargeIcon(appIconDrawable)
} else {
    notificationBuilder.setSmallIcon(appIconDrawable);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!