Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android AttributeSet API

android AttributeSet API

編輯:關於Android編程

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.
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved