简体   繁体   English

android:style.xml或dimens.xml还是其他? 扑朔迷离

[英]android : style.xml or dimens.xml or what else? confusing

Now, am trying to be a good Android developer and put all my textsize and other size specifications, and all the styles (like, say, button color, etc) in XML files. 现在,我想成为一名优秀的Android开发人员,并将我所有的textsize和其他大小规格以及所有样式(例如按钮颜色等)放入XML文件。 Am trying to read up on these. 我正在尝试阅读这些内容。 In a Stackoverflow thread, I read about dimens.xml . 在Stackoverflow线程中,我了解了dimens.xml So I created a dimens.xml under each values- directory (like values-ldpi, values-mdpi, blah blah) and put one dimens.xml in each. 因此,我在每个values-目录下创建了dimens.xml(例如values-ldpi,values-mdpi,等等),并在每个目录中放置了一个dimens.xml。 It works fine. 工作正常。 Now, I want to put some style information in the XML, like, a button color. 现在,我想在XML中添加一些样式信息,例如按钮颜色。 Should I put the attribute in the same file ie dimens.xml? 我应该将属性放在同一个文件(即dimens.xml)中吗? I read in one thread that dimens.xml is only for dimensions, and not for style related info. 我读过一个线程,dimens.xml仅用于尺寸,而不用于样式相关的信息。 In another thread , I read that the name of the XML doesn't matter. 在另一个线程中 ,我读到XML的名称无关紧要。 Now, what is a good practice? 现在,什么是好习惯? Keep style.xml and dimens.xml separate ? 是否将style.xml和dimens.xml分开? Or put everything in one xml? 还是将所有内容都放在一个xml中? And if, say, for a textview, I want to have both style (like color), and also textsize information in XML, then should I (1) put both color & textSize in styles.xml, or (2) put color in styles.xml and textSize in dimens.xml? 并且,例如,对于文本视图,我想同时拥有样式(如颜色)和XML中的文本大小信息,那么我应该(1)将color&textSize都放入styles.xml中,还是(2)将颜色放入dimens.xml中的styles.xml和textSize?

Keep style.xml and dimens.xml separate ? 是否将style.xml和dimens.xml分开?

As soon as style.xml already exists for reasons like these (button colors, text color, themes, etc.) then I believe that you should keep them separate. 由于这些原因(按钮颜色,文本颜色,主题等),一旦style.xml已经存在,那么我认为您应该将它们分开。

And if, say, for a textview, I want to have both style (like color), and also textsize information in XML, then should I (1) put both color & textSize in styles.xml, or (2) put color in styles.xml and textSize in dimens.xml? 并且,例如,对于文本视图,我想同时拥有样式(如颜色)和XML中的文本大小信息,那么我应该(1)将color&textSize都放入styles.xml中,还是(2)将颜色放入dimens.xml中的styles.xml和textSize?

I would do the (2). 我会做的(2)。 (Although I can't blame anyone who would do the (1).). (尽管我不能怪任何会做(1)的人。)。 As far as I know there's no best practice guidance on that. 据我所知,目前尚无最佳实践指导。 I do it the (2) way basically because I see dimen.xml as a place to host pixel-related values. 我之所以采用(2)方式,基本上是因为我将dimen.xml视为托管像素相关值的地方。 But this is my preference. 但这是我的偏爱。

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

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