首页 > 解决方案 > 为什么 bigText 不返回 Style 类型

问题描述

为什么 bigText() 方法不会在 setStyle 中返回 Style 类型,或者为什么 setStyle 需要 Style Type ?

看图片

https://drive.google.com/open?id=1BRYjh4OQp83-VcFmcRjXQpU798asu-16

我正在尝试发出通知

    NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "kdfjds", NotificationManager.IMPORTANCE_DEFAULT);
        notificationManager.createNotificationChannel(notificationChannel);
    }

    Notification.Builder notification = new Notification.Builder(this);

    notification.setSmallIcon(R.drawable.ic_launcher_foreground);

    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher_background);

    notification.setLargeIcon(largeIcon);
    notification.setContentTitle("order");
    notification.setContentText("You have new order");

    Intent goToOrder = new Intent(this,MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this,97,goToOrder,0);
    notification.setContentIntent(pendingIntent);
    notification.setStyle(new NotificationCompat.BigTextStyle().bigText(this.getString(R.string.charging_reminder_notification_title)));
    notification.setAutoCancel(true);


    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            notification.setPriority(Notification.PRIORITY_HIGH);
        }
    }



    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notificationManager.notify(NOTIFICATION_ID,notification.build());
    }

标签: androidnotificationsstyles

解决方案


尝试使用Notification.BigTextStyle()而不是NotificationCompat.BigTextStyle().

PS - 这里的问题是您正在尝试混合软件包,您实际上是在尝试android.support.v4.app.NotificationCompat.BigTextStyleandroid.app.Notification.Style预期的时间使用。


推荐阅读