问题标签 [android-darkmode]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1047 浏览

android - When to override dark mode in Activity lifecycle?

I'm trying to adopt best practice for managing light and dark mode in my app, based on guidance here and here.

Based on this, I am using a theme inherited from DayNight:

In Manifest:

In themes.xml:

This has the desired effect of opening up an Activity in a light or dark theme, based on the device's system setting.

But I want to give the user the option of overriding the mode, e.g. to be always dark (even if the system is in light mode).

But when the system is in light mode, I'm finding that that my Activity initially opens up with a light theme (flash of white), before I get the chance to switch over to the dark theme. I'm switching as soon as I possibly can in the Activity lifecycle:

But even then, I'm getting an annoying "flash of light" before the Activity switches over to dark.

How do I avoid the flash of light?

0 投票
1 回答
573 浏览

flutter - 在商店道具更改上颤动 MobX 更改主题

我正在开发一个使用 MobX 作为状态管理器的简单颤振应用程序。这个应用程序有两个主题:

  1. 黑暗模式
  2. 灯光模式

当 MobX 商店状态发生变化时,我希望我的应用程序在运行时在这两个主题之间切换。这是我的 main.dart:

我希望appStore.isDarkMode用户何时更改整个应用程序主题更新并做出反应,但它只会在第一次应用程序渲染时更改,并且在商店更改时不会自行更新。
任何想法?

0 投票
3 回答
728 浏览

nativescript-angular - 无法在 Nativescript 上仅使用 Light 或 Dark 主题

我正在使用 Angular 8.2 和带有 scss 主题的 @nativescript/theme 2.2.1 开发 Nativescript(版本 6.3.3)应用程序。无论系统模式(深色/浅色)如何,我都尝试仅使用深色(或仅浅色)主题,但似乎没有任何效果。我遵循本指南https://github.com/NativeScript/theme并使用自定义颜色变量将深色变量设置为浅色变量,但它不起作用。有人可以支持我吗?

0 投票
0 回答
115 浏览

android-notifications - 自定义通知视图中的android图像在暗模式下反转(android 10.0)

  1. 当我使用 systemPic 样式时,使用系统 xml,效果很好。
  1. 但是当我使用自定义布局时,通知中的图像就像一个负面图像: 原始图像反转图像
0 投票
1 回答
1520 浏览

android - 在 RecyclerView 中未正确解析暗模式颜色

我正在尝试实现夜间模式,但我遇到了问题:CardView没有将颜色更改为night值,但活动正确地将其背景更改为夜间颜色值。

请帮助理解问题。

MainActivity

MainActivity布局

适配器

RecyclerView.ViewHolder

RecyclerView.ViewHolderxml

colors.xml

colors.xml夜晚

0 投票
0 回答
160 浏览

android - 启用暗模式时 MODE_NIGHT_YES 和 MODE_NIGHT_FOLLOW_SYSTEM 之间的差异

我在清单上有一个具有此属性的设置活动:

我有

但是当我在手机和应用程序上设置暗模式时,我使用 setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); 一切都很好,相反,当我在手机上设置禁用暗模式并设置 AppCompatDelegate.MODE_NIGHT_YES 时出现问题。

我举了一个例子(Android 10 的像素 3a)禁用手机上的暗模式和 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); 在应用程序上 在此处输入图像描述

手机上启用暗模式和 AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); 在此处输入图像描述

所以……怎么了?请帮我。

0 投票
2 回答
3320 浏览

android - Android 暗模式:海拔不改变表面颜色

我正在关注谷歌的优秀博客文章为我的应用程序制作一个黑暗的主题,但我没有看到任何关于如何在我的视图(按钮、应用程序栏等)上获得高程效果的参考。例如,当我将我的应用程序主题设置为 <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar"> 并制作一个按钮或卡片时:

我希望看到使对象看起来更亮的效果,因为在深色主题中使用了半透明的白色覆盖层来暗示海拔或比背景更接近光源。相反,我的按钮、操作栏等与背景颜色相同,因此不可见。

我的问题是:

  1. 我必须手动实现这个高程功能还是由材料库提供?
  2. 如果我让它在 Android 10+ 上自动运行,我是否必须实施手动解决方案以在版本 9 及更早版本上实现向后兼容性?
0 投票
3 回答
1566 浏览

android - Android Activity 在使用暗模式时被实例化两次

我的启动器活动,即 MainActivity 在使用时被实例化了两次, AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) 这导致了两次网络调用并做出了奇怪的行为。

有什么可以控制它并只初始化一次吗?我试过使用 launchMode = "singleTop" 和 "singleInstance"

0 投票
0 回答
112 浏览

android - 如何在不丢失数据的情况下重新启动视图

我正在开发一个应用程序来数字化我公司的旧表格。每个表单都有许多输入值(RadioGroups、EditText、Checkboxes)。该应用程序需要一个动态的暗模式,以日出和日落为导向。因此,当我在表单中工作时,如果太阳下山,它应该更改 App-Theme。

我的本地广播服务(由 MainActivity 启动)检查实际时间是否在日落和日出之间并发送广播。前台活动接收到广播,应该将主题更改为深色,但不会丢失输入值。

我尝试的一切都不起作用,因为我在 Receiver 函数中操作并在 onCreate-Method 中设置 ContentView:

非常重要的是,我不会丢失输入中的值,所以我不能使用startActivity(intent)&finish()recreate()

有人知道问题的解决方案吗?

0 投票
1 回答
1935 浏览

java - Android Q:如何以编程方式为所有应用程序全局设置暗模式?

我想将 Android Q 主题更改为深色模式,但不仅限于一个应用程序。我想将它应用到整个设备。这可能吗?如果是,怎么做?