android - 通知在 API 17 下可见,但在 API 13 下不可见

标签 android android-notifications textcolor

我正在使用 NotificationCompat.Builder 制作一个简单的通知,然后将其添加到通知栏。在运行 API 17 的 AVD 上,可以按预期在通知下拉列表中看到通知。但是在运行 API 13 的 AVD 上,无法看到通知的标题/文本/信息(可能是由于黑色背景上的黑色文本)。

在寻找问题的解决方案时,我发现了以下内容:Custom notification colors and text colors但这似乎只适用于为通知使用自定义布局的情况。

这是我的代码:

    private static int notificationId = 1;
private void displayNotification() {

    // create an Intent to launch the Show Notification activity
    // (when user selects the notification on the status bar)
    Intent i = new Intent(this, ShowNotificationActivity.class);
    // pass it some value
    i.putExtra(ShowNotificationActivity.NOTIF_ID, notificationId);

    // wrap it in a PendingIntent
    PendingIntent pendingIntent = PendingIntent.getActivity(this, notificationId, i, 0);

    // create the notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle("This is the Title #" + notificationId);
    builder.setContentText("This is the Text");
    builder.setContentInfo("This is the Info");
    builder.setContentIntent(pendingIntent);
    builder.setSmallIcon(android.R.drawable.ic_notification_overlay);
    builder.setAutoCancel(true);
    Notification notif = builder.build();

    // display the notification
    NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
    nm.notify(notificationId, notif);

    notificationId++;
}

我曾希望发布一些屏幕截图,显示 API 17 和 API 13 下的下拉通知,但显然我没有足够的“声誉点数”来发布图像。所以我想书面描述就足够了:

在 API 17 下,通知下拉菜单显示通知的图标(红点)、标题和文本。背景颜色为黑色,文字颜色为白色。

在 API 13 下,只有图标(红点)可见。背景颜色是黑色,我怀疑文字颜色也可能是黑色。

我怀疑我遗漏了一些明显的东西,但我是新手,非常感谢任何指点。

最佳答案

当我将您的代码复制粘贴到我的空 Activity 中时,出现了几个错误(您的代码似乎不完整)。我添加了这些行以使其工作:

int notificationId = 1;
Intent intent = new Intent(this, MyActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

//Here goes your code.

我刚刚在 3.2 模拟器上测试了您的代码,这就是通知的样子:

enter image description here

我认为,它应该是这样的。

你能不能用我的代码测试一下,让我知道它是否有效?

关于android - 通知在 API 17 下可见,但在 API 13 下不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15098110/

相关文章:

android - 如何在android中实现html5

Android:如何在 SAX 解析器中解析相同的标签?

android - 如何在通知 FCM Android 上添加按钮

android - 当用户点击我的通知时,我想在那里显示一个 AlertDialog

android - 如何在运行时更改 TextColor auf ActionBarCompat MenuItem?

javascript - 更改 onclick 文本颜色在某些文本中不起作用

twitter-bootstrap - 使用 Twitter Bootstrap,如何自定义一页的 h1 文本颜色,而将其他页面保留为默认颜色?

java - 使用 Android Studio 中的开关启用/禁用 editText

java - 如何通过单击按钮在应用程序图标上设置通知号码?

android - React Native 中不包含 NativeModules