小编Cod*_*rop的帖子

Android NotificationCompat.BigTextStyle 错误

我在 AndroidStudio 1.4.1 中设置了一个通知,并遇到了 setStyle 函数的错误。

这是代码:

NotificationCompat.Builder builder =
                new NotificationCompat.Builder(this);
        builder
                .setSmallIcon(R.drawable.ic_assignment)
                .setContentTitle("Easteregg found!");
        String easter = "You found our Easteregg! Well done";
        //custom colour
        int color = getResources().getColor(R.color.primaryColor);
        builder.setContentText(easter);
        builder.setColor(color);
        builder.setStyle(new NotificationCompat.BigTextStyle(easter));
        Notification notification = builder.build();
        NotificationManagerCompat.from(this).notify(0, notification);
        Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        // Vibration pattern
        long[] pattern = {0, 100, 250, 320};
        v.vibrate(pattern, -1);
Run Code Online (Sandbox Code Playgroud)

打电话时

builder.setStyle(new NotificationCompat.BigTextStyle(easter));
Run Code Online (Sandbox Code Playgroud)

我收到通知

BigTextStyle 无法应用于 java.lang.string

由于我使用了 Google https://www.youtube.com/watch?v=-iog_fmm6mE提供的示例,所以我很困惑。我也尝试了一些基本的错误修复,但没有解决问题,所以我问你。

如果有人能帮助我解决这个问题,我将不胜感激。

提前致谢。

PS:如果我遗漏了什么,请提出来,我会尽力为您提供所需的所有信息。

notifications android android-studio

3
推荐指数
1
解决办法
639
查看次数

标签 统计

android ×1

android-studio ×1

notifications ×1