如何在 Android 中自动显示浅色主题和深色主题的不同资源?
据我了解,Android 有两个内置主题,浅色和深色。我希望我的应用程序根据用户使用的主题显示不同的资源(而不是让用户在我的应用程序中显式指定主题!)。这可能吗?如果是这样,是否可以通过 xml 资源来完成,或者是否需要编程方法?
注意:是的,我已阅读 http://d.android.com/guide /topics/ui/themes.html 至少三次。它似乎告诉我如何做就是为我的元素设置一个特定的主题或样式,而不是正确显示浅色/深色元素。
As I understand, there are two built in themes for Android, Light and Dark. I want my application to display different resources based on which theme the user is using (NOT by having the user explicitly specify a theme in my app!). Is this possible? If so, is it possible to do via xml resources, or is a programmatic approach required?
Note: Yes, I've read http://d.android.com/guide/topics/ui/themes.html at least thrice. It seems like all it tells me how to do is set one specific theme or styles to my element, rather than displaying light/dark elements correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,可以通过 XML 资源来完成。
来自 https://developer.android.com/preview/features/darktheme#themes_and_styles:
所以是的,有资源限定符,请参阅 https:/ /developer.android.com/guide/topics/resources/providing-resources.html#NightQualifier
:
night
和notnight
后缀。我发现 Material theme website 非常擅长解释这一点,但最重要的部分是:
Yes, it can be done via XML resources.
From https://developer.android.com/preview/features/darktheme#themes_and_styles:
So yes, there are resource qualifiers for that, see https://developer.android.com/guide/topics/resources/providing-resources.html#NightQualifier
:
night
andnotnight
suffixes.I find Material theme website to be pretty good at explaining this but the most important part is:
您可以在这个网站上检查替代的可绘制文件夹。
http://developer.android.com/guide/topics/resources/providing -resources.html
此外,此文档可能会有所帮助。
http://developer.android.com/guide/topics/ui/themes.html
对于常规主题:我不知道 Android 中有任何相关功能,您可能需要自己开发。
This is a site you can check for alternative drawable folders.
http://developer.android.com/guide/topics/resources/providing-resources.html
Also, this document might be helpful.
http://developer.android.com/guide/topics/ui/themes.html
For regular themes: I'm not aware of any functions in Android about that, you might need to develop it yourself.