问题描述
有关于声明-设置样式
标记,使我们可以为组件声明自定义样式precious的小文件。我发现有效值这个列表为格式
属性在 ATTR
标记。虽然这是很好的,只要它去,它没有解释如何使用其中的一些价值观。浏览<一href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/values/attrs.xml;h=6370696708a2b7ecb561015629801bd380fe486a;hb=HEAD">attr.xml (Android的源标准属性),我发现,你可以做这样的事情:
&LT;! - 最突出的文字颜色。 - &GT;
&LT; attr指示NAME =textColorPrimary格式=引用|色/&GT;
在格式
属性可以明显被设置为值的组合。 presumably的格式
属性可帮助解析器间preT的实际样式值。后来我发现这attr.xml:
&LT;! - 默认的文本字体。 - &GT;
&LT; attr指示NAME =字体&GT;
&LT;枚举名=正常值=0/&GT;
&LT;枚举名=SANS值=1/&GT;
&LT;枚举名=衬线值=2/&GT;
&LT;枚举名=等宽值=3/&GT;
&LT; / ATTR&GT;
&LT;! - 默认的文本字体样式。 - &GT;
&LT; attr指示NAME =文字样式&GT;
&LT;标志名称=正常值=0/&GT;
&LT;标志名称=黑体值=1/&GT;
&LT;标志名称=斜体值=2/&GT;
&LT; / ATTR&GT;
这两个似乎声明一组允许值的指定样式。
所以,我有两个问题:
- 什么,可以采取一组
枚举
值,另一种可以在一组中的一个样式属性之间的区别标志
值? - 有谁知道的任何更好的文档如何
声明-设置样式
作品(除逆向工程的Android源$ C $ C)?
还有这里的这个问题:定义定制ATTRS ,提供的部分的资料,但并不多。
这<一href="http://staticallytyped.word$p$pss.com/2011/04/16/android-custom-xml-attributes-and-views/">post 。它有大约国旗和枚举好消息:
在我看来,真正的价值,你可以在现实中加入由你可以从中获取有限的属性。此处检查的AttributeSet
类引用更多的提示。
- 布尔(
getAttributeBooleanValue
), - 花车(
getAttributeFloatValue
), - 整型(
getAttributeIntValue
), - 在整数(如
getAttributeUnsignedIntValue
), - 和字符串(
getAttributeValue
)
There's precious little documentation about the declare-styleable
tag by which we can declare custom styles for components. I did find this list of valid values for the format
attribute of the attr
tag. While that's nice as far as it goes, it doesn't explain how to use some of those values. Browsing attr.xml (the Android source for the standard attributes), I discovered that you can do things like:
<!-- The most prominent text color. -->
<attr name="textColorPrimary" format="reference|color" />
The format
attribute can evidently be set to a combination of values. Presumably the format
attribute helps the parser interpret an actual style value. Then I discovered this in attr.xml:
<!-- Default text typeface. -->
<attr name="typeface">
<enum name="normal" value="0" />
<enum name="sans" value="1" />
<enum name="serif" value="2" />
<enum name="monospace" value="3" />
</attr>
<!-- Default text typeface style. -->
<attr name="textStyle">
<flag name="normal" value="0" />
<flag name="bold" value="1" />
<flag name="italic" value="2" />
</attr>
Both of these seem to declare a set of allowed values for the indicated style.
So I have two questions:
- What's the difference between a style attribute that can take on one of a set of
enum
values and one that can take on a set offlag
values? - Does anyone know of any better documentation for how
declare-styleable
works (other than reverse engineering the Android source code)?
There's this question here: Defining custom attrs with some info, but not much.
And this post . It has good info about flags and enums:
As I see it, the real values you can add in reality to an attribute is limited by what you can obtain from it. Check the AttributeSet
class reference here for more hints.
You can obtain:
- booleans (
getAttributeBooleanValue
), - floats (
getAttributeFloatValue
), - ints (
getAttributeIntValue
), - ints (as
getAttributeUnsignedIntValue
), - and strings (
getAttributeValue
)
这篇关于声明Android中设置样式属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!