http://www.geekchamp.com/tips/all-about-wp7-isolated-storage---read-and-save-images#][1]我正在尝试在通知中添加图标,但通知图标非常小,并未覆盖整个空间。
我在每个资源文件夹中都有正确的图像尺寸。
我通知的代码:
Intent myIntent = new Intent(getApplicationContext(), Lock.class);
PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(),
0,
myIntent,
Intent.FLAG_ACTIVITY_NEW_TASK);
myNotification = new NotificationCompat.Builder(getApplicationContext())
.setContentTitle("Invisible Screen Lock")
.setContentText("Lock Your Screen")
.setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_SOUND)
.setSmallIcon(R.drawable.launcher)
.setOngoing(true)
.build();
notificationManager =
(NotificationManager)getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);
如何让图标正确显示?
答案 0 :(得分:1)
使用setLargeIcon(icon)如下:
myNotification = new NotificationCompat.Builder(getApplicationContext())
.setContentTitle("Invisible Screen Lock")
.setContentText("Lock Your Screen")
.setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_SOUND)
.setLargeIcon(icon)
.setOngoing(true)
.build();
答案 1 :(得分:1)
尝试提供一个大图标
Notification.Builder nb = new Notification.Builder(context)
.setContentTitle("title")
.setContentText("content")
.setAutoCancel(true)
.setLargeIcon(drawableToBitmap(YOUR_DRAWABLE))
.setSmallIcon(R.drawable.small_icon)
.setTicker(s.getText());
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(100, nb.build());
添加此方法
public static Bitmap drawableToBitmap (Drawable drawable) {
Bitmap bitmap = null;
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if(bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}
if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}