5

我想在图片上画点东西,完成之后,它就是一个位图。我想将此位图作为其图标添加到通知中。但它的图标必须是一个 int Id 。我怎样才能做到?谢谢你的回答~~~~请帮帮我!

4

6 回答 6

5

从这篇文章中,我知道通知图标将获取资源图像。所以你不能在小图标中做动态。但是你可以为 Api Level 11 的大图标做。

为此,您可以Notificaiton.Builder 在此处使用参考

其他方式也有。也就是说,您可以更改下拉通知时出现的图标。为此,您必须使用RemoteViews

参考这里

于 2012-10-25T05:25:36.040 回答
2

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

于 2012-10-25T05:10:56.917 回答
0

尝试这个:

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)文件夹中。将任何位图分配给图标,您将获得所需的输出。

于 2012-10-25T05:21:20.947 回答
0

如果您使用的是 Android Studio,您始终可以将原始图像转换为图像资源,并且应该生成您可以轻松使用的正确图像格式,即分配一个 ID。您可以选择覆盖默认资源名称或使用其他名称。

于 2014-09-22T15:46:37.493 回答
0

尝试使用 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>
于 2014-04-02T03:03:08.077 回答
0

将您的位图转换为可绘制对象,然后您可以将其用作对话框中的通知图标。

于 2012-10-25T05:13:02.470 回答