如何从通知中删除时间计数器?

时间:2018-04-05 10:10:30

标签: android timestamp android-notifications

如何删除' now'以及我的应用中通知布局的下拉箭头。我使用单一布局进行通知,但它正在扩展。我将高度保持在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);

See this image of Android notifications

2 个答案:

答案 0 :(得分:0)

只需使用

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

答案 1 :(得分:0)

根据你可以使用的Documentation

setWhen(long when)
setShowWhen(boolean show);

默认情况下setShowWhen为真,因此您可以将其设置为setShowWhen(false)以删除时间戳。