android AttributeSet API

android   AttributeSet API

public interface

AttributeSet

android.util.AttributeSet
已知间接子类

XmlResourceParser

类概述



属性的集合,通常在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.
时间: 2024-10-29 14:55:00

android AttributeSet API的相关文章

android AttributeSet API 之开发案例

android AttributeSet API 之开发案例 在通过xml文件构造view组件的时候,往往都要使用到AttributeSet和defStyle这个两个参数. public class myButton extends Button{ public myButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated

使用Android中API建议的方式实现SQLite数据库的增、删、改、查的操作

package com.examp.use_SQLite.dao; import java.util.ArrayList; import java.util.List; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import com.examp

安卓一键ROOT, android root api sdk 服务支持

android 一键root sdk已经开发完毕,支持PC 及手机端: 鉴于现在手机端的需求比较大,特提供SDK外放服务:以及ROOT技术支持: 商务合作  ROOT后您可以: 1.删除系统应用,定制个性化系统 2.各种暗扣(当然现在国内环境不行,但是您有渠道还是可以的) 3.静默安装各种推广APP 4.打压竞争对手APP 5.后台静默刷流量 6.完全控制他人手机 7.等等等 安卓一键root sdk 服务,安卓root技术支持, android root sdk, android root a

Android 中文API (65) —— BluetoothClass[蓝牙]

前言 本章内容是android.bluetooth.BluetoothClass,为Android蓝牙部分的章节翻译.用于描述远端设备的类型,特点等信息,通过getBluetoothClass()方法获取代表远端设备属性的BluetoothClass对象.版本为Android 2.3   r1,翻译来自中山大学的"Android Club SYSU",欢迎访问他们的WIKI:http://www.android-wiki.net,再次感谢"Android Club SYSU&

Android 中文API (67) —— BluetoothClass.Device.Major

前言 本章内容是android.bluetooth.BluetoothClass.Device.Major,为Android蓝牙部分的章节翻译,版本为Android 2.3   r1,翻译来自中山大学的"Android Club SYSU",欢迎访问他们的WIKI:http://www.android-wiki.net,再次感谢"Android Club SYSU"!期待你一起参与Android中文API的翻译,联系我 [email protected]. 声明 欢

Android 中文API (68) —— BluetoothClass.Service

前言 本章内容是 android.bluetooth.BluetoothClass.Service,为Android蓝牙部分的章节翻译,版本为 Android 2.3   r1,翻译来自中山大学的"Android Club SYSU",欢迎访问他们的WIKI:http://www.android-wiki.net,再次感谢"Android Club SYSU"!期待你一起参与Android中文API的翻译,联系我 [email protected]. 声明 欢迎转载

android sdk api结构解析

一.系统级:android.accounts android.app     1.OS 相关         android.os         android.os.storage         android.hardware(传感器)         android.security         android.drm(这个应该是为所有app服务的)     2.VM 相关         dalvik.system         dalvik.bytecode 二.程序框架  

使用Fiddler分析Android版API

使用Fiddler分析Android版API 首先要准备的工具: android手机+知乎日报APP: Fiddler(大名鼎鼎Telerik出的,Telerik): 局域网. 原理很简单,打开Fiddler,将它设置成为一个代理,然后将同一局域网中的Android手机代理设置为Fiddler所在的电脑. 之后Android手机所有的HTTP请求都会先经过代理(Fiddler所在的电脑),Fiddler当然也能捕获到请求的各种数据.(注意如果捕获的回话过多,请通过Fiddler右侧的Filter

Android 中文API (66) —— BluetoothClass.Device

前言 本章内容是android.bluetooth.BluetoothClass.Device,为Android蓝牙部分的章节翻译,版本为Android 2.3   r1,翻译来自中山大学的"Android Club SYSU",欢迎访问他们的WIKI:http://www.android-wiki.net,再次感谢"Android Club SYSU"!期待你一起参与Android中文API的翻译,联系我 [email protected]. 声明 欢迎转载,但请