简体   繁体   English

Android Lollipop通知图标太小

[英]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. 问题是,该图标确实很小,并且没有填充整个圆圈,它在其周围留下了浅蓝色(TouchWiz,我认为是白色的)边框。 How do apps like WhatsApp get it to fill the full circle and not be resized? 诸如WhatsApp之类的应用程序如何使其充满整个圈子而不被调整大小? 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 您可以调用setLargeIcon来在提名抽屉中设置图像

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

} }

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

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