简体   繁体   中英

Android Lollipop notification icon too small

I started to add notifications to my app and want it to display my app icon in the notification drawer. The problem is, the icon is really small and does not fill out the entire circle, it leaves a light-blue (TouchWiz, I think white on stock) border around it. How do apps like WhatsApp get it to fill the full circle and not be resized? In the status bar it looks fine btw.

My code to display a notification:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                                                        .setSmallIcon(R.drawable.widget_icon)
                                                        .setContentTitle("My notification")
                                                        .setContentText("Hello World!");
        Intent resultIntent = new Intent(this, MainActivity.class);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(MainActivity.class);
        stackBuilder.addNextIntent(resultIntent);

        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.setContentIntent(resultPendingIntent);

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        mNotificationManager.notify(1, mBuilder.build());

you can call setLargeIcon to set the image in nofication drawer

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setLargeIcon(bitmap);

if you are not satisfied with the size of the icon provided by system. you can draw it yourself. simple code below:

public class NotificationIconDrawer {

private Canvas mCanvas;
private Bitmap mBmp;

public NotificationIconDrawer() {
    mBmp = Bitmap.createBitmap(yourWidth, yourHeight, Config.RGB_565);
    mCanvas = new Canvas(mBmp);
}

public Bitmap draw() {
    mCanvas.drawBitmap(bitmap, matrix, paint);
    mCanvas.save();
    return mBmp;
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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