关于使用NotificationComat导致android2.3及以下版本无法显示自定义布局的解决方法.

  大伙都知道 android-support-v4为我们提供了很多兼容的解决方案, 其中就有关于通知栏的. 

NotificationCompat, 顺利成章操刀显示通知.

eg:

Intent intent = new Intent();
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setTicker("ticker");    //未拉开时上方滚动的
builder.setSmallIcon(R.drawable.icon);    //每个版本显示有所区别2.3及以下显示为左边的, 2.3以上显示在时间下面的.
builder.setDefaults(Notification.DEFAULT_SOUND);
builder.setVibrate(info.isVibrate() ? VibrationType.type_ssl : new long[]{0});
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
builder.setContent(RemoteViews);
mNotification = builder.build();

但是这样很可惜, 在api10以下也就是2.3及以下版本是无法显示出自定义布局的.

只需要把老版本的方法再写一遍就ok了, 这可能是support-v4的一个bug.

if (Build.VERSION.SDK_INT <= 10) {
  mNotification.contentView = RemoteViews;
}

 

  

posted @ 2013-12-16 15:51  小草房Jason  阅读(560)  评论(1编辑  收藏  举报