Android NotificationCompat.BigTextStyle 错误
Android NotificationCompat.BigTextStyle error
我在 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);
调用时
builder.setStyle(new NotificationCompat.BigTextStyle(easter));
我收到通知
BigTextStyle could not be applied to java.lang.string
因为我使用了 Google https://www.youtube.com/watch?v=-iog_fmm6mE 提供的示例,所以我很困惑。我也尝试了一些基本的错误修复,但没有解决问题,所以我问你。
如果有人能帮助我,我将不胜感激。
提前致谢。
P.S.: 如果我遗漏了什么,请提出来,我会尽力为您提供所需的所有信息。
该视频中的代码片段不正确。当您 运行 遇到 API 未按预期执行的问题时,我强烈建议 going to the API documentation first。
在这种情况下,问题是 BigTextStyle
没有采用字符串的构造函数。相反,您需要先创建一个 BigTextStyle
,然后调用其他三个可用方法中的一个(或多个)来设置内容。
您可能正在寻找这样的东西:
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(easter));
我在 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);
调用时
builder.setStyle(new NotificationCompat.BigTextStyle(easter));
我收到通知
BigTextStyle could not be applied to java.lang.string
因为我使用了 Google https://www.youtube.com/watch?v=-iog_fmm6mE 提供的示例,所以我很困惑。我也尝试了一些基本的错误修复,但没有解决问题,所以我问你。
如果有人能帮助我,我将不胜感激。
提前致谢。
P.S.: 如果我遗漏了什么,请提出来,我会尽力为您提供所需的所有信息。
该视频中的代码片段不正确。当您 运行 遇到 API 未按预期执行的问题时,我强烈建议 going to the API documentation first。
在这种情况下,问题是 BigTextStyle
没有采用字符串的构造函数。相反,您需要先创建一个 BigTextStyle
,然后调用其他三个可用方法中的一个(或多个)来设置内容。
您可能正在寻找这样的东西:
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(easter));