API-TypedArray

来源:互联网 发布:对待新事物的态度知乎 编辑:程序博客网 时间:2024/06/06 00:41

TypedArray | Android Developers
https://developer.android.google.cn/reference/android/content/res/TypedArray.html

简介:Container for an array of values that were retrieved with obtainStyledAttributes(AttributeSet, int[], int, int) or obtainAttributes(AttributeSet, int[]). Be sure to call recycle() when done with them. The indices used to retrieve values from this structure correspond to the positions of the attributes given to obtainStyledAttributes.

翻译过来就是:

  • 一个用来检索属性值的容器;
  • 使用完之后,必须recycle();
  • index下标用来检索属性,相当于属性在obtainStyledAttributes(获取样式属性)中的position.

再来看方法:

返回值 方法名 boolean getBoolean(int index, boolean defValue) int getColor(int index, int defValue) float getDimension(int index, float defValue) Drawable getDrawable(int index) float getFloat(int index, float defValue) int getInt(int index, int defValue) int getInteger(int index, int defValue) String getString(int index) CharSequence getText(int index)

其他方法:

返回值 方法名 解释 ColorStateList getColorStateList(int index) int getDimensionPixelOffset(int index, int defValue) int getDimensionPixelSize(int index, int defValue) float getFraction(int index, int base, int pbase, float defValue) int getIndex(int at) int getIndexCount() int getLayoutDimension(int index, int defValue) int getLayoutDimension(int index, String name) String getNonResourceString(int index) String getPositionDescription() int getResourceId(int index, int defValue) Resources getResources() CharSequence[] g etTextArray(int index) boolean getValue(int index, TypedValue outValue) boolean hasValue(int index) int length() TypedValue peekValue(int index) void recycle()
0 0