gpt4 book ai didi

android - 带有远程 View 的 Android 10 上的黑暗通知

转载 作者:行者123 更新时间:2023-12-02 13:32:36 27 4
gpt4 key购买 nike

当我在 Android 10 中将显示模式更改为深色时,根据此处显示的图像获取深色(黑色)通知。我尝试更改文本颜色,但它没有重新调整。我正在使用远程 View 来创建自定义通知。如何为深色模式和浅色模式更改不同的远程内容 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

最佳答案

我通过创建 解决了问题值夜文件夹。我在 中添加了 colors.xml值夜文件夹并覆盖我在正常 中使用的颜色值-colors.xml 并在远程 View 设计文件中应用文本颜色。
引用。 https://medium.cobeisfresh.com/how-to-implement-day-night-mode-in-your-android-app-2f21907f9b0a
更新:
最新要防止的另一件事Xiaomi devices在您处于黑暗模式时强制执行黑暗应用程序设计。
theme.xml 中应用以下参数到你的主题风格。

<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>

关于android - 带有远程 View 的 Android 10 上的黑暗通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60509276/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com