【发布时间】:2017-02-15 22:05:09
【问题描述】:
如何更改通知中的图标和大图标?我正在尝试这段代码:
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Notification notification = builder
.setSmallIcon(android.R.drawable.stat_notify_more)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle("title")
.setContentText("text").build();
notificationManager.notify(666, notification);
这很好用,通知已显示。但是通知仍然像application icon一样,而不是来自android drawable的"stat_notifi_more",为什么?
而且STATUS BAR ICON(左上角电池、wifi 等旁边的通知小图标)也没有显示!
有人可以帮我解决这个问题吗?
编辑:我有 lollipop 5.1.1 和 android 24 (sdk)
EDIT2:
通知图标(OK)(96x96px):
状态栏图标(24x24px)(不行,默认应用程序图标):
真实状态栏图标:
通知来源:
// Using RemoteViews to bind custom layouts into Notification
RemoteViews remoteViews = new RemoteViews(getPackageName(),
R.layout.notification_layout);
// Set Notification Title
String strtitle = "title";
// Set Notification Text
String strtext = "text";
// Open NotificationView Class on Notification Click
Intent intent = new Intent(this, MainActivity.class);
// Send data to NotificationView Class
intent.putExtra("title", strtitle);
intent.putExtra("text", strtext);
// Open NotificationView.java Activity
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
// Locate and set the Image into customnotificationtext.xml ImageViews
remoteViews.setImageViewResource(R.id.imagenotileft, R.drawable.stacionar_xhdpi_green);
// Locate and set the Text into customnotificationtext.xml TextViews
remoteViews.setTextViewText(R.id.title, "title");
remoteViews.setTextViewText(R.id.text, "content");
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.wall_black)
.setTicker("t")
.setContentIntent(pIntent)
.setContent(remoteViews);
// Create Notification Manager
NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Build Notification with Notification Manager
notificationmanager.notify(0, builder.build());
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imagenotileft"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/imagenotileft" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:layout_toRightOf="@+id/imagenotileft" />
</RelativeLayout>
【问题讨论】:
-
问题出在notificationId上。你已经调用了魔鬼通知。你现在需要驱除你的代码。
标签: android notifications statusbar