当我添加通知时:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.plus)
.setContentTitle(title)
.setAutoCancel(true)
.setContentText(text)
.setSound(RingtoneManager .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setLargeIcon(bm);
我看到大图标和小图标:
如何只设置大图标,不小。如果只使用setLargeIcon,我根本看不到通知,只是声音警报。
小图标是强制性的。如果你没有设置一个大的,你会在你选择的颜色(setColor)的圆圈中间放大你的小图标。
如果我是你,我会把那个空白的E放在透明的背景上为小人,并为圆圈设置一个红色。
获取小图标ID,然后尝试隐藏它
int smallIconId = ctx.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
if (smallIconId != 0) {
if (notification.contentView!=null)
notification.contentView.setViewVisibility(smallIconId, View.INVISIBLE);
}
试着看看这个post它也会有所帮助
我在api 18,23(三星j1,galaxy S6)上测试代码工作正常
根据之前的答案,您也可以隐藏已消耗的视图:
int smallIconId = AnghamiApp.getContext().getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
if (smallIconId != 0) {
notification.contentView.setViewVisibility(smallIconId, View.INVISIBLE);
notification.bigContentView.setViewVisibility(smallIconId, View.INVISIBLE);
}
您可以创建自定义通知,然后在大型通知区域中显示您想要的任何内容。在这里查看和示例TutorialsFace: Build all types of Notifications in Android
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("Test")
.setContentText("Hii There")
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.smallicon))
.setAutoCancel(true)
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(123, notification);
}
}