【问题标题】:Notifications visible under API 17, but invisible under API 13通知在 API 17 下可见,但在 API 13 下不可见
【发布时间】:2013-02-28 05:35:48
【问题描述】:

我正在使用 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 下,只有图标(红点)可见。背景颜色是黑色的,我怀疑文字颜色也可能是黑色的。

我怀疑我遗漏了一些明显的东西,但我是新手,希望得到任何指点。

【问题讨论】:

    标签: android android-notifications textcolor


    【解决方案1】:

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

    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 模拟器上测试了您的代码,这就是通知的样子:

    我相信它应该是这样的。

    您能用我的代码进行测试并告诉我它是否有效吗?

    【讨论】:

    • 感谢您的回复,安东。在一次(错误引导的)简洁尝试中,我省略了一些代码。我已将该代码添加到我的帖子中。它与您的一些小细节有所不同,我认为这与此问题无关。
    • 我已经用你的代码尝试了我的示例,但我仍然观察到相同的行为(在下拉菜单中看不到标题和文本)。 (您显示的屏幕截图是我希望看到的。)我尝试了几个不同的 AVD 模拟 3.2,但我在所有这些上都得到了相同的行为。我在制作 AVD 时感觉自己在黑暗中磕磕绊绊,能否提供您使用的 AVD 的详细信息?
    • 问题不大可能出在 AVD 上,但让我们检查一下。你能运行一个不同的应用程序来创建一个通知并检查它的文本是否正确吗? IE。设置一个闹钟并在它响起时打盹 - 你会看到一个闹钟通知。
    • 我使用时钟程序设置了一个闹钟,然后我将它打盹。在通知栏中,我看到了已打盹警报的条目。我可以看到图标(小白色时钟),但没有其他细节。 (我会发布一个屏幕截图,但我没有足够的权限。)
    • 顺便说一句:我创建了 3 个 3.2 AVD。莫名其妙(至少对我来说),其中两个在通知下拉菜单中有黑色背景,一个有白色背景。我可以在白色背景的 AVD 中看到我的通知。
    猜你喜欢
    • 1970-01-01
    • 2021-03-11
    • 2021-09-19
    • 1970-01-01
    • 2017-09-26
    • 1970-01-01
    • 2011-06-24
    • 1970-01-01
    • 2015-11-19
    相关资源
    最近更新 更多