Android:通过使用主题,我是否只能为每个属性拍摄一次? Android 中有没有类似 CSS 的东西?
这里他们写道:
要将样式定义应用为主题,您必须将该样式应用于 Android 清单中的活动或应用程序。当您这样做时,该视图中的每个视图 活动或申请将适用 它支持的每个属性。为了 例如,如果您应用 CodeFont 样式从前面的示例改为 Activity,然后是所有 View 元素 支持文本样式属性 应用它们。
那么,当我将 TextColor 设置为红色时,所有带有文本的元素是否都会更改为红色?没有像 CSS 样式表中那样强大的说明符吗?我只是认为样式(style="@style/CodeFont"
)的概念是可行的。
Here they write:
To apply a style definition as a theme, you must apply the style to an Activity or application in the Android manifest. When you do so, every View within the
Activity or application will apply
each property that it supports. For
example, if you apply the CodeFont
style from the previous examples to an
Activity, then all View elements that
support the text style properties will
apply them.
So, when I set TextColor to Red, do ALL Elements with Text change to red?? Arent there powerful specifier like in CSS style-sheets? I just see the concept of styles (style="@style/CodeFont"
) practicable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了响应您的评论,您可能会通过属性
textAppearance
找到您想要的内容。在此处打开 theme.xml 文件:
https:// android.googlesource.com/platform/frameworks/base/+/froyo-release/core/res/res/values/themes.xml
如果您查找 textAppearance,您会注意到各种条目,例如:
这允许您在某种程度上,可以在整个应用程序中设置组件的样式,如 Maragues 示例所示。
因此,虽然不可能完全控制列表视图、滚动视图等内所有子元素的样式,但对控制某些基于文本的组件(例如 TextView 和/或按钮)的样式的支持有限。
In response to your comments you might find what your looking for with the property
textAppearance
.Open the themes.xml file here:
https://android.googlesource.com/platform/frameworks/base/+/froyo-release/core/res/res/values/themes.xml
If you do a find for textAppearance you notice various entries such as:
This allows you to some extent to style Components throughout your application as shown in the Maragues example.
So whilst its not possible to fully control the style of all child elements withint say a listview, scroll view etc, there is some limited support for controlling the styles some Text based components such as the TextView and or Button.
如果您阅读了引用的文本下方:
要为应用程序的所有活动设置主题,请打开 AndroidManifest.xml 文件并编辑标签以包含带有样式名称的 android:theme 属性
如果您希望主题仅应用于应用程序中的一个 Activity,请改为将 android:theme 属性添加到标记中。
之后,它描述了如何继承和重写属性,只需像CSS:
如果您喜欢某个主题,但想要调整它,只需将该主题添加为自定义主题的父主题即可。例如,您可以修改传统的对话框主题以使用您自己的背景图像,如下所示:
然后,从 CustomTextView 进行迭代
设计 XML 布局后,您可以继承主题并覆盖
我认为您应该再次阅读的 属性您自己链接的页面,解释得很好:)
If you read just below the text you quoted:
To set a theme for all the activities of your application, open the AndroidManifest.xml file and edit the tag to include the android:theme attribute with the style name
If you want a theme applied to just one Activity in your application, then add the android:theme attribute to the tag instead.
And a little bit after that, it describes how to inherit and override properties, just like CSS:
If you like a theme, but want to tweak it, just add the theme as the parent of your custom theme. For example, you can modify the traditional dialog theme to use your own background image like this:
Then, to interit from CustomTextView
Once designing the XML layout, you can inherit a theme and override the properties
I think you should read again the page you yourself linked, it's well explained :)