无法切换夜间模式 [英] Unable to switch Night mode

查看:107
本文介绍了无法切换夜间模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更改夜间模式在我的手机上不起作用(在模拟器中有效)

Changing night mode doesn't work on my mobile (it works in emulator)

夜间模式设置为我的手机的系统模式(黑暗模式)

night mode is set to my mobile's system mode(dark mode)

由于新的android studio的存在,因此启动代码中包含默认的夜间模式主题

Since the new android studio there is default night mode theme in the starter code

我只需要使用Light模式制作一个应用 我检查了许多解决方案,可以在其中使用AppCompatDelegate方法更改主题 此处的示例

I need to make a app with only Light mode I've checked many solutions where we can change the theme using AppCompatDelegate method example here, and docs

推荐答案

您可以通过活动文件将主题设置为亮或暗模式.这是您需要的代码的片段:

You could set the theme to light or dark mode via the activity file. Here is the snipit of code you need:

    fun useAppContext() {
    // Context of the app under test.
    val appContext = InstrumentationRegistry.getInstrumentation().targetContext
    assertEquals("com.fcs.darktheme", appContext.packageName)
}

您可以查看在其中找到的视频.我完全使用Java,该原理对我有用.我在该视频中评论了您是否需要Java代码.这是在这里用kotlin完成的: https://www. youtube.com/watch?v=bWLnf2nqTl4&lc=UgximPI3XmiVgRa9k3N4AaABAg.9HePgMqRxF-9HeU3b16R-b&feature=em-comments

You can check out the video that I found this in. I persoanlly use Java and the principle worked for me. I commented in that video should you need the Java code. It is done with kotlin here: https://www.youtube.com/watch?v=bWLnf2nqTl4&lc=UgximPI3XmiVgRa9k3N4AaABAg.9HePgMqRxF-9HeU3b16R-b&feature=em-comments

这篇关于无法切换夜间模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆