[英]How should you work with Themes in Android?
I have been practising my skills with android (Kotlin), and I am having issues with styling the UI, with most solutions here not working.我一直在使用 android (Kotlin) 练习我的技能,但我在设置 UI 样式时遇到了问题,这里的大多数解决方案都不起作用。 It feels like there's some default style overriding what I am trying to achieve because often than not the changes are visible in the layout creator GUI in android studio but not in the app itself.感觉就像有一些默认样式覆盖了我想要实现的内容,因为这些更改通常在 android studio 的布局创建者 GUI 中可见,但在应用程序本身中不可见。 I even noticed the apps base dark or light theme setting affects the Ui looks which should not be the case for me.我什至注意到应用程序基于深色或浅色主题设置会影响 UI 外观,这对我来说不应该是这样。
The greatest challenge I have had is trying to change the app theme with both methods not working or working only to a certain degree which often leaves things quite off:我遇到的最大挑战是尝试更改应用程序主题,而这两种方法都不起作用或仅在一定程度上起作用,这通常会使事情变得很糟糕:
toggling using this AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES)
使用此AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES)
切换
or explicitly changing the theme using setTheme(R.style.Theme_Dark)
或使用setTheme(R.style.Theme_Dark)
显式更改主题
Is there something I am not considering or I do not know?有什么我没有考虑或我不知道的吗? I am happy to provide any more information for better context.我很高兴提供更多信息以获得更好的背景信息。 Thanks in advance!提前致谢!
So I have done a little more reading and seen some of the underlining issues I was experiencing.所以我做了更多的阅读,并看到了我遇到的一些强调问题。 I'll be updating this are I learn more.如果我了解更多,我会更新这个。
Adding this line in more Theme xml file prevented this giving me more freedom.在更多主题 xml 文件中添加这一行可以防止这给我更多的自由。
<item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
(27-6-2022) (27-6-2022)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.