Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何更改自定义通知背景颜色(Oreo及以上)?_Android_Kotlin_Notifications_Androidx_Remoteview - Fatal编程技术网

Android 如何更改自定义通知背景颜色(Oreo及以上)?

Android 如何更改自定义通知背景颜色(Oreo及以上)?,android,kotlin,notifications,androidx,remoteview,Android,Kotlin,Notifications,Androidx,Remoteview,我试图将背景色(白色)设置为我的自定义通知视图,但在android X上,通知带有黑色背景。以下是生成通知的代码: context?.let { val notificationLayout = RemoteViews(it.packageName, R.layout.custom_notification_collapsed) val notificationLayoutExpanded = RemoteViews(it.packageName, R.la

我试图将背景色(白色)设置为我的自定义通知视图,但在android X上,通知带有黑色背景。以下是生成通知的代码:

  context?.let {

        val notificationLayout = RemoteViews(it.packageName, R.layout.custom_notification_collapsed)
        val notificationLayoutExpanded = RemoteViews(it.packageName, R.layout.custom_notification)

        notificationLayout.setImageViewResource(R.id.iv_icon, R.drawable.custom_notification_icon)
        notificationLayout.setTextViewText(R.id.tv_app_name, it.getString(R.string.app_name))
        notificationLayout.setTextViewText(R.id.time_stamp, it.getString(R.string.just_now))

        notificationLayoutExpanded.setImageViewResource(R.id.iv_icon, R.drawable.custom_notification_icon)
        notificationLayoutExpanded.setTextViewText(R.id.tv_app_name, it.getString(R.string.app_name))
        notificationLayoutExpanded.setTextViewText(R.id.tv_popup_content, it.getString(R.string.class_meeting_for_class_name_is_beginning_please_check_in_if_you_are_present))
        notificationLayout.setTextViewText(R.id.time_stamp, it.getString(R.string.just_now))


        // Create an explicit intent for an Activity in your app
        val intent = Intent(it, SplashActivity::class.java).apply {
            flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
        }
        val pendingIntent: PendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
        val fullScreenPendingIntent = PendingIntent.getActivity(context, 0,
                intent, PendingIntent.FLAG_UPDATE_CURRENT)

        var builder = NotificationCompat.Builder(it, AppConstants.CHANNEL_ID)
                .setSmallIcon(R.drawable.custom_notification_icon)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setContent(notificationLayoutExpanded)
                .setAutoCancel(true)
                .setColor(resources.getColor(R.color.mdtp_white))
                .setFullScreenIntent(fullScreenPendingIntent, true)
                .setCustomContentView(notificationLayoutExpanded)
                .setCustomBigContentView(notificationLayoutExpanded)


        var customNotificationCompat: NotificationManagerCompat = NotificationManagerCompat.from(it)
        customNotificationCompat.notify(0, builder.build())

    }