Темное уведомление о Android 10 с удаленным просмотром - PullRequest
0 голосов
/ 03 марта 2020

Получение темного (черного) уведомления в соответствии с изображением, показанным здесь, когда я изменил режим отображения на Темный в Android 10. Я пытался изменить цвет текста, но он не отражается. Я использую Remote view для создания пользовательских уведомлений. Как изменить цвета текста при удаленном просмотре контента для темного и светлого режимов? Вот мой код:

        val contentViewBig = RemoteViews(context.applicationContext.packageName, R.layout.design_custom_notification)
        contentViewBig.setTextViewText(R.id.tvNotificationTitle, notificationTitle)
        contentViewBig.setTextViewText(R.id.tvNotificationBody, notificationBody)

        val nId = Random().nextInt()

        val pendingIntent = PendingIntent.getActivity(context,
                nId /* Request code */, intent, PendingIntent.FLAG_UPDATE_CURRENT)
        val channelId = context.getString(R.string.default_notification_channel_id)
        val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)

        val notificationBuilder = NotificationCompat.Builder(context, channelId)
                .setSmallIcon(R.drawable.ic_notification)
                .setAutoCancel(true)
                .setCustomContentView(contentViewBig)
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setLights(Color.WHITE, 2000, 3000)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent)


        // Since android Oreo notification channel is needed.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

            val channel = NotificationChannel(channelId,
                    context.resources.getString(R.string.app_name), NotificationManager.IMPORTANCE_HIGH)
            channel.description = context.resources.getString(R.string.app_name)
            channel.setShowBadge(true)
            channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
            notificationManager?.createNotificationChannel(channel)
        }

        if (notificationManager != null) {
            notificationManager.notify(nId, notificationBuilder.build())
            wakeLockScreen(context)
        }

enter image description here

1 Ответ

0 голосов
/ 04 марта 2020

Я решил проблему, создав папку values-night . Я добавил цвета. xml внутри values-night папки и переопределил цвета, которые я использовал в обычных значениях - цветах. xml и применяя цвет текста в файле дизайна удаленного просмотра .

Реф. https://medium.cobeisfresh.com/how-to-implement-day-night-mode-in-your-android-app-2f21907f9b0a

...