search

Home  >  Q&A  >  body text

android-ui - 关于android控件布局样式的问题

初学android没几天,界面设计在网上看范例的时候发现一个问题,为什么有些的控件样式写在drawable/XXX.xml目录里,用@drawable/引用?为什么有的控件样式写在values/style.xml文件里,用@style/引用?有的控件样式甚至两个方法都用上了,这样操作完成一个项目的样式结构岂不是很混乱?

在网上看到还有的源码,用style就可以解决的,他用drawable文件解决,本人不得其解,希望同仁帮忙解答困惑。

迷茫迷茫2872 days ago746

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 12:59:46

    The style of a control includes many attributes, such as background, foreground (ImageView), appearance animation, disappearing animation, etc.

    The files in the drawable folder are defined for a certain attribute. For example, if I want to define a red rounded rectangle background, I will write an xml file with a shape tag in the drawable folder. Then reference

    via @drawable

    The files in the style folder are defined for a certain type of control (a collection of several properties). There are generally two situations when defining in the style folder

    1. It is necessary to repeatedly define a type of control. For example, if a large number of fade-in and fade-out effects are used in the APP, then the fade-in and fade-out effects will be defined as a style and referenced through @style
    2. You need to modify the styles provided by the system, for example, change the color of Theme.Holo’s ActionBar to red, and leave everything else unchanged

    reply
    0
  • Cancelreply