android AttributeSet API

android   AttributeSet API

public interface

AttributeSet

android.util.AttributeSet
已知间接子类

类概述


属性的集合,通常在xml文档中出现,一般来说,你不会想直接去使用它,而是通过能够为你解释属性的Resources.Theme.obtainStyledAttributes()来使用它。特别的,Resources API 将转换引用资源(好比.xml文件中的"@string/my_label")为你希望的类型。如果,你直接使用AttributeSet,那么你就要手动的去检查你的资源应用(通过getAttributeResourceValue(int, int))并且如果需要的话你还要自己去查找资源。直接使用AttributeSet同样也会在检查属性时破坏Application的themes和styles.

这个接口也提供了一种通过使用XmlPullParser的Xml.asAttributeSet()的方法高效的从编译过的.xml文件检索数据的机制,通常情况下会返回一个通过XmlPullParser的接口实现,但它是在编译的XML资源结合时更加有用:

 XmlPullParser parser = resources.getXml(myResouce);
 AttributeSet attributes = Xml.asAttributeSet(parser);

这种实现方法不像 XmlPullParser 的综合实现。在编译你的资源时,它高效实现了对appt已生成的预算信息检索的优化,例如getAttributeFloatValue(int, float)返回的是已经存储在你的编译资源中的浮点数而不是运行时的./xml文件中的原始字符串

这个借口还提供了包含在编译过的xml文件中在原始xml文件中不存在附加信息。例如getAttributeNameResource(int)返回的是与特定的XML相关联的资源标识符属性名称。

概述


公有方法
abstract boolean getAttributeBooleanValue( String namespace,  String attribute, boolean defaultValue)
返回‘attribute’ 的Boolean值,默认 defaultValue
abstract boolean getAttributeBooleanValue(int index, boolean defaultValue)
返回序列号为index的‘attribute’ 的Boolean值,默认defaultValue
abstract int getAttributeCount()
返回属性集中的属性数
abstract float getAttributeFloatValue(int index, float defaultValue)
Return the float value of attribute at 'index'.
abstract float getAttributeFloatValue( String namespace,  String attribute, float defaultValue)
Return the float value of 'attribute'.
abstract int getAttributeIntValue( String namespace,  String attribute, int defaultValue)
Return the integer value of 'attribute'.
abstract int getAttributeIntValue(int index, int defaultValue)
Return the integer value of attribute at 'index'.
abstract int getAttributeListValue( String namespace,  String attribute,  String[] options, int defaultValue)
Return the index of the value of 'attribute' in the list 'options'.
abstract int getAttributeListValue(int index,  String[] options, int defaultValue)
Return the index of the value of attribute at 'index' in the list 'options'.
abstract  String getAttributeName(int index)
Returns the name of the specified attribute.
abstract int getAttributeNameResource(int index)
Return the resource ID associated with the given attribute name.
abstract int getAttributeResourceValue( String namespace,  String attribute, int defaultValue)
Return the value of 'attribute' as a resource identifier.
abstract int getAttributeResourceValue(int index, int defaultValue)
Return the value of attribute at 'index' as a resource identifier.
abstract int getAttributeUnsignedIntValue(int index, int defaultValue)
Return the integer value of attribute at 'index' that is formatted as an unsigned value.
abstract int getAttributeUnsignedIntValue( String namespace,  String attribute, int defaultValue)
Return the boolean value of 'attribute' that is formatted as an unsigned value.
abstract  String getAttributeValue(int index)
Returns the value of the specified attribute as a string representation.
abstract  String getAttributeValue( String namespace,  String name)
Returns the value of the specified attribute as a string representation.
abstract  String getClassAttribute()
Return the value of the "class" attribute or null if there is not one.
abstract  String getIdAttribute()
Return the value of the "id" attribute or null if there is not one.
abstract int getIdAttributeResourceValue(int defaultValue)
Return the integer value of the "id" attribute or defaultValue if there is none.
abstract  String getPositionDescription()
Returns a description of the current position of the attribute set.
abstract int getStyleAttribute()
Return the value of the "style" attribute or 0 if there is not one.

公有方法


public abstract boolean getAttributeBooleanValue (String namespace, String attribute, boolean defaultValue)
添加于  API 级别 1

Return the boolean value of 'attribute'.

参数
namespace 要检索的‘attribute’命名空间
attribute 要检索的‘attribute’
defaultValue ‘attribute’没有找到的默认返回值
返回值
  • Resulting value.
public abstract boolean getAttributeBooleanValue (int index, boolean defaultValue)
添加于  API 级别 1

Return the boolean value of attribute at 'index'.

参数
index Index of the desired attribute, 0...count-1.
defaultValue What to return if the attribute isn't found.
返回值
  • Resulting value.
public abstract int getAttributeCount ()
添加于  API 级别 1

Returns the number of attributes available in the set.

返回值
  • A positive integer, or 0 if the set is empty.
public abstract float getAttributeFloatValue (int index, float defaultValue)
添加于  API 级别 1

Return the float value of attribute at 'index'.

参数
index Index of the desired attribute, 0...count-1.
defaultValue What to return if the attribute isn't found.
返回值
  • Resulting value.
public abstract float getAttributeFloatValue (String namespace, String attribute, float defaultValue)
添加于  API 级别 1

Return the float value of 'attribute'.

参数
namespace Namespace of attribute to retrieve.
attribute The attribute to retrieve.
defaultValue What to return if the attribute isn't found.
返回值
  • Resulting value.
public abstract int getAttributeIntValue (String namespace, String attribute, int defaultValue)
添加于  API 级别 1

Return the integer value of 'attribute'.

参数
namespace Namespace of attribute to retrieve.
attribute The attribute to retrieve.
defaultValue What to return if the attribute isn't found.
返回值
  • Resulting value.
public abstract int getAttributeIntValue (int index, int defaultValue)
添加于  API 级别 1

Return the integer value of attribute at 'index'.

参数
index Index of the desired attribute, 0...count-1.
defaultValue What to return if the attribute isn't found.
返回值
  • Resulting value.
public abstract int getAttributeListValue (String namespace, String attribute, String[] options, int defaultValue)
添加于  API 级别 1

Return the index of the value of 'attribute' in the list 'options'.

参数
namespace Namespace of attribute to retrieve.
attribute Name of attribute to retrieve.
options List of strings whose values we are checking against.
defaultValue Value returned if attribute doesn't exist or no match is found.
返回值
  • Index in to 'options' or defaultValue.
public abstract int getAttributeListValue (int index, String[] options, int defaultValue)
添加于  API 级别 1

Return the index of the value of attribute at 'index' in the list 'options'.

参数
index Index of the desired attribute, 0...count-1.
options List of strings whose values we are checking against.
defaultValue Value returned if attribute doesn't exist or no match is found.
返回值
  • Index in to 'options' or defaultValue.
public abstract String getAttributeName (int index)
添加于  API 级别 1

Returns the name of the specified attribute.

参数
index Index of the desired attribute, 0...count-1.
返回值
  • A String containing the name of the attribute, or null if the attribute cannot be found.
public abstract int getAttributeNameResource (int index)
添加于  API 级别 1

Return the resource ID associated with the given attribute name. This will be the identifier for an attribute resource, which can be used by styles. Returns 0 if there is no resource associated with this attribute.

Note that this is different than getAttributeResourceValue(int, int) in that it returns a resource identifier for the attribute name; the other method returns this attribute's value as a resource identifier.

参数
index Index of the desired attribute, 0...count-1.
返回值
  • The resource identifier, 0 if none.
public abstract int getAttributeResourceValue (String namespace, String attribute, int defaultValue)
添加于  API 级别 1

Return the value of 'attribute' as a resource identifier.

Note that this is different than getAttributeNameResource(int) in that it returns a the value contained in this attribute as a resource identifier (i.e., a value originally of the form "@package:type/resource"); the other method returns a resource identifier that identifies the name of the attribute.

参数
namespace Namespace of attribute to retrieve.
attribute The attribute to retrieve.
defaultValue What to return if the attribute isn't found.
返回值
  • Resulting value.
public abstract int getAttributeResourceValue (int index, int defaultValue)
添加于  API 级别 1

Return the value of attribute at 'index' as a resource identifier.

Note that this is different than getAttributeNameResource(int) in that it returns a the value contained in this attribute as a resource identifier (i.e., a value originally of the form "@package:type/resource"); the other method returns a resource identifier that identifies the name of the attribute.

参数
index Index of the desired attribute, 0...count-1.
defaultValue What to return if the attribute isn't found.
返回值
  • Resulting value.
public abstract int getAttributeUnsignedIntValue (int index, int defaultValue)
添加于  API 级别 1

Return the integer value of attribute at 'index' that is formatted as an unsigned value. In particular, the formats 0xn...n and #n...n are handled.

参数
index Index of the desired attribute, 0...count-1.
defaultValue What to return if the attribute isn't found.
返回值
  • Resulting value.
public abstract int getAttributeUnsignedIntValue (String namespace, String attribute, int defaultValue)
添加于  API 级别 1

Return the boolean value of 'attribute' that is formatted as an unsigned value. In particular, the formats 0xn...n and #n...n are handled.

参数
namespace Namespace of attribute to retrieve.
attribute The attribute to retrieve.
defaultValue What to return if the attribute isn't found.
返回值
  • Resulting value.
public abstract String getAttributeValue (int index)
添加于  API 级别 1

Returns the value of the specified attribute as a string representation.

参数
index Index of the desired attribute, 0...count-1.
返回值
  • A String containing the value of the attribute, or null if the attribute cannot be found.
public abstract String getAttributeValue (String namespace, String name)
添加于  API 级别 1

Returns the value of the specified attribute as a string representation. The lookup is performed using the attribute name.

参数
namespace The namespace of the attribute to get the value from.
name The name of the attribute to get the value from.
返回值
  • A String containing the value of the attribute, or null if the attribute cannot be found.
public abstract String getClassAttribute ()
添加于  API 级别 1

Return the value of the "class" attribute or null if there is not one. Equivalent to getAttributeValue(null, "class").

返回值
  • The class attribute's value or null.
public abstract String getIdAttribute ()
添加于  API 级别 1

Return the value of the "id" attribute or null if there is not one. Equivalent to getAttributeValue(null, "id").

返回值
  • The id attribute's value or null.
public abstract int getIdAttributeResourceValue (int defaultValue)
添加于  API 级别 1

Return the integer value of the "id" attribute or defaultValue if there is none. Equivalent to getAttributeResourceValue(null, "id", defaultValue);

参数
defaultValue What to return if the "id" attribute isn't found.
返回值
  • int Resulting value.
public abstract String getPositionDescription ()
添加于  API 级别 1

Returns a description of the current position of the attribute set. For instance, if the attribute set is loaded from an XML document, the position description could indicate the current line number.

返回值
  • A string representation of the current position in the set, may be null.
public abstract int getStyleAttribute ()
添加于  API 级别 1

Return the value of the "style" attribute or 0 if there is not one. Equivalent to getAttributeResourceValue(null, "style").

返回值
  • The style attribute's resource identifier or 0.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值