zoukankan      html  css  js  c++  java
  • 关于使用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;
    }

      

    欢迎分享转载,转载请注明出处 http://www.cnblogs.com/fangyucun
  • 相关阅读:
    第04组(64)需求分析报告
    实验 7:OpenDaylight 实验——Python 中的 REST API 调用
    结对编程作业
    第01组 Alpha冲刺(5/6)
    第01组 Alpha冲刺(4/6)
    第01组 Alpha冲刺 (3/6)
    第01组 Alpha冲刺(2/6)
    第01组 Alpha冲刺(1/6)
    第01组(17)需求分析报告
    第01组(17)团队展示
  • 原文地址:https://www.cnblogs.com/fangyucun/p/3476900.html
Copyright © 2011-2022 走看看