【问题标题】:how to remove time counter from notification?如何从通知中删除时间计数器?
【发布时间】:2018-04-05 10:10:29
【问题描述】:

如何从我的应用中的通知布局中删除“现在”和下拉箭头。我正在使用单一布局进行通知,但它正在扩展。我将高度保持在 64dp 和 50dp 但尺寸没有变化

    // Get the layouts to use in the custom notification
    RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_small);
    //RemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(), R.layout.notification_large);
    notificationLayout.setTextViewText(R.id.otpText,otp);
    // Apply the layouts to the notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
    builder.setSmallIcon(R.drawable.ic_launcher_foreground)
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
            .setCustomContentView(notificationLayout)
            .setPriority(PRIORITY_MAX)
            .setDefaults(DEFAULT_SOUND)
            .setColor(getResources().getColor(R.color.colorAccent))
            .setDefaults(DEFAULT_VIBRATE)
            .setContentIntent(pendingIntent);

【问题讨论】:

    标签: android timestamp android-notifications


    【解决方案1】:

    只需使用

    builder.setSmallIcon(R.drawable.ic_launcher_foreground)
    ...
           .setWhen(0)
    ...
    

    【讨论】:

      【解决方案2】:

      根据Documentation你可以使用:

      setWhen(long when)
      setShowWhen(boolean show);
      

      默认setShowWhen为true,所以可以设置为setShowWhen(false)来去掉时间戳。

      【讨论】:

      • 箭头呢??
      • 去掉时间戳后箭头有什么作用?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-05
      • 1970-01-01
      • 1970-01-01
      • 2019-01-12
      相关资源
      最近更新 更多