我想在图片上画点东西,完成之后,它就是一个位图。我想将此位图作为其图标添加到通知中。但它的图标必须是一个 int Id 。我怎样才能做到?谢谢你的回答~~~~请帮帮我!
6 回答
You can put image file in res->drawable (or drawable-hdpi,ldpi,mdpi), for example notify.png and use it
myNotification = new Notification(R.id.notify, "Notification!", System.currentTimeMillis());
or
Try using AnimationDrawable's. You can use them to combine multiple drawables into a single one, and select the one you want to display. I really think, this is the way to go.
More info: AnimationDrawable
Off course, you will have to provide individual drawables for all your Integers you want to display, but this way, you can easily change the appearance of your notifications
尝试这个:
NotificationManager notificationManager=
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon=R.drawable.ic_launcher;
CharSequence text="Notification Text";
long when=System.currentTimeMillis();
Notification notification=new Notification(icon, text, when);
notificationManager.notify(Constants.NOTIFICATION_ID, notification);
我采用了默认图像,您可以将图像文件保存在 res->drawable(或 drawable-hdpi、ldpi、mdpi)文件夹中。将任何位图分配给图标,您将获得所需的输出。
如果您使用的是 Android Studio,您始终可以将原始图像转换为图像资源,并且应该生成您可以轻松使用的正确图像格式,即分配一个 ID。您可以选择覆盖默认资源名称或使用其他名称。
尝试使用 xml 绘制图像,并将其放入像 n.icon = R.drawable.x 这样的图标中;
可绘制/x.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/write_normal_battery1" />
<item android:drawable="@drawable/notif_0" android:left="5.5dip" android:right="13.5dip" />
<item android:drawable="@drawable/notif_9" android:left="13.5dip" android:right="5.5dip" />
</layer-list>
将您的位图转换为可绘制对象,然后您可以将其用作对话框中的通知图标。