Android 以编程方式获取可设置样式的属性的名称
有没有一种方法可以通过编程方式获取可设置样式的属性的名称:Android 以编程方式获取可设置样式的属性的名称,android,attributes,Android,Attributes,有没有一种方法可以通过编程方式获取可设置样式的属性的名称: 例如,我想从R.styleable.TextView\u Text整数值中获取“Text”。您的可设置样式为: <declare-styleable name="TextView"> <attr name="DataContext" format="string" /> <attr name="Text" format="string" /> </declare-sty
例如,我想从R.styleable.TextView\u Text
整数值中获取“Text”
。您的可设置样式为:
<declare-styleable name="TextView">
<attr name="DataContext" format="string" />
<attr name="Text" format="string" />
</declare-styleable>
在代码中:
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TextView);
int n = a.getIndexCount();
for (int i = 0; i < n; i++) {
int attr = a.getIndex(i);
switch (attr) {
case R.styleable.TextView_DataContext:
title = a.getString(attr);
break;
case R.styleable.TextVie_Text:
//Any you want
break;
default:
Log.d("TAG", "Unknown attribute for " + getClass().toString() + ": " + attr);
break;
}
}
a.recycle();
TypedArray a=getContext().ActainStyleDattributes(attrs,R.styleable.TextView);
int n=a.getIndexCount();
对于(int i=0;i
custom:DataContext="@string/xxxx"
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TextView);
int n = a.getIndexCount();
for (int i = 0; i < n; i++) {
int attr = a.getIndex(i);
switch (attr) {
case R.styleable.TextView_DataContext:
title = a.getString(attr);
break;
case R.styleable.TextVie_Text:
//Any you want
break;
default:
Log.d("TAG", "Unknown attribute for " + getClass().toString() + ": " + attr);
break;
}
}
a.recycle();