简体   繁体   English

在Android中,为我的style.xml或dimens.xml定义细微调整的最佳方法是什么?

[英]In Android, what is the best way to define small tweaks to my style.xml or dimens.xml?

In Android, we can specify resources depending on the screen size by appending qualifiers to the folder names, such as "res/values-xlarge". 在Android中,我们可以通过将限定符附加到文件夹名称(例如“ res / values-xlarge”)来根据屏幕尺寸指定资源。 I am working on a large enterprise application that has some fairly big styles.xml and dimens.xml files. 我正在一个大型企业应用程序上工作,该应用程序具有一些很大的styles.xml和dimens.xml文件。 Obviously, I do not want to duplicate the entire files for each screen size that needs some small tweaks. 显然,我不想为每个需要一些细微调整的屏幕尺寸复制整个文件。

What is the best way to specify tweaks to styles, dimens, and similar resources without duplicating the common parts? 在不重复通用部分的情况下,指定对样式,变暗和类似资源进行调整的最佳方法是什么?

Just specify the values you want to modify in the different folders, and leave the common ones on the lowest level. 只需在不同文件夹中指定要修改的值,然后将常用值保留在最低级别即可。 Styles will be a bit harder to do, but you can actually make a common style with all common values, then specify the differences in a different style that inherits from the first one. 样式会比较难做,但是实际上您可以使用所有公共值创建一个公共样式,然后使用从第一个样式继承的另一种样式指定差异。

For example, you can have a style A in res/values/ that has the common behaviour for all the different styles. 例如,您可以在res / values /中使用样式A,该样式对于所有不同样式都具有相同的行为。 However, in large screens (hdpi and xhdpi) you want to have a common behaviour you don't want in little screens: Just create a B style that inherits from A and has that behaviour in res/values, then specify the differences in res/values-xhdpi and res/values-hdpi. 但是,在大屏幕(hdpi和xhdpi)中,您希望有一种常见的行为,而在小屏幕中则不希望出现:仅创建从A继承并在res / values中具有该行为的B样式,然后指定res之间的差异/ values-xhdpi和res / values-hdpi。

If Android cannot find a value in R in a "proper" folder, it will search elsewhere until it finds said value. 如果Android在“适当”文件夹中的R中找不到值,它将在其他位置搜索,直到找到所述值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM