有一个 style文件
文件中的部分代码如下<style name="style_text_title">
<item name="android:textSize">25px</item>
<item name="android:textColor">#ec9237</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>TypedArray arr = context.getResources().obtainTypedArray(resId);
然后开始遍历
for(int i=0; i<arr.length(); i++){
key = arr.getString(i);//??? 不知道如何获取key 就是item的name属性
value = arr.getText(i).toString();
Log.i(TAG, key + "---" + value);
Log.i(TAG, arr.toString());
}
我捣鼓了好久。也没办法实现, 求助有设么方法可以获取指定资源ID的xml定义(注意最好用系统内置的方法, 原因是效率高)比如说
obj.getBySomeMethod(R.id.style_text_title) // 我可以获取到整个 xml的定义(如顶部xml)
文件中的部分代码如下<style name="style_text_title">
<item name="android:textSize">25px</item>
<item name="android:textColor">#ec9237</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>TypedArray arr = context.getResources().obtainTypedArray(resId);
然后开始遍历
for(int i=0; i<arr.length(); i++){
key = arr.getString(i);//??? 不知道如何获取key 就是item的name属性
value = arr.getText(i).toString();
Log.i(TAG, key + "---" + value);
Log.i(TAG, arr.toString());
}
我捣鼓了好久。也没办法实现, 求助有设么方法可以获取指定资源ID的xml定义(注意最好用系统内置的方法, 原因是效率高)比如说
obj.getBySomeMethod(R.id.style_text_title) // 我可以获取到整个 xml的定义(如顶部xml)
解决方案 »
- 如何读取一个apk文件中的包名以及主activity名
- android问题
- 判断直线与矩形有交点
- Android/Java中如何实现多项目间复用代码
- 关于AlertDialog的问题,急,在线等回答
- 如何在 EditText 输入框中获取光标位置偏移量?高手快来啊
- layout布局错误,提示"error: Error: No resource found that matches the ..."
- Eclipse Android XML编辑的问题
- 调用系统相机,“保存”那个步骤我能不能跳过而直接保存
- 想自学android系统适配
- animation是不是只能监听Button
- ScrollView如何实现记录的位置,下次启动程序自动定位到上次位置
obtainStyledAttributes();看官方TextView源代码 很长不全贴了
TypedArray a =
context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.TextView, defStyle, 0);....
...
..
.
/*
* Look the appearance up without checking first if it exists because
* almost every TextView has one and it greatly simplifies the logic
* to be able to parse the appearance first and then let specific tags
* for this View override it.
*/
TypedArray appearance = null;
int ap = a.getResourceId(com.android.internal.R.styleable.TextView_textAppearance, -1);
if (ap != -1) {
appearance = context.obtainStyledAttributes(ap,
com.android.internal.R.styleable.
TextAppearance);
}
if (appearance != null) {
int n = appearance.getIndexCount();
for (int i = 0; i < n; i++) {
int attr = appearance.getIndex(i); switch (attr) {
case com.android.internal.R.styleable.TextAppearance_textColorHighlight:
textColorHighlight = appearance.getColor(attr, textColorHighlight);
break; case com.android.internal.R.styleable.TextAppearance_textColor:
textColor = appearance.getColorStateList(attr);
break; case com.android.internal.R.styleable.TextAppearance_textColorHint:
textColorHint = appearance.getColorStateList(attr);
break; case com.android.internal.R.styleable.TextAppearance_textColorLink:
textColorLink = appearance.getColorStateList(attr);
break; case com.android.internal.R.styleable.TextAppearance_textSize:
textSize = appearance.getDimensionPixelSize(attr, textSize);
break; case com.android.internal.R.styleable.TextAppearance_typeface:
typefaceIndex = appearance.getInt(attr, -1);
break; case com.android.internal.R.styleable.TextAppearance_textStyle:
styleIndex = appearance.getInt(attr, -1);
break;
}
} appearance.recycle();
}
....
..
.
http://www.cmd100.com/bbs/forum.php?mod=viewthread&tid=178996&page=1#pid194335