5
我想导出Facebook Android SDK作为我的项目中使用的JAR。如何动态加载R.styleable资源?
这需要动态加载所有资源。
例如,我必须作出改变与此类似:
//findViewById(R.id.com_facebook_login_activity_progress_bar).setVisibility(View.VISIBLE);
int viewID = getResources().getIdentifier("com_facebook_login_activity_progress_bar", "id", getPackageName());
findViewById(viewID).setVisibility(View.VISIBLE);
注释的线示出了原始的,并且下面的2行示出了变化我提出动态地加载相同的资源。
Facebook SDK声明了一个R.styleable资源,我无法弄清楚如何动态加载它。这里是原代码:
private void parseAttributes(AttributeSet attrs) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.com_facebook_profile_picture_view);
setPresetSize(a.getInt(R.styleable.com_facebook_profile_picture_view_preset_size, CUSTOM));
isCropped = a.getBoolean(R.styleable.com_facebook_profile_picture_view_is_cropped, IS_CROPPED_DEFAULT_VALUE);
a.recycle();
}
然后在attrs.xml,以下声明:
<declare-styleable name="com_facebook_profile_picture_view">
<attr name="preset_size">
<!-- Keep in sync with constants in ProfilePictureView -->
<enum name="small" value="-2" />
<enum name="normal" value="-3" />
<enum name="large" value="-4" />
</attr>
<attr name="is_cropped" format="boolean" />
</declare-styleable>
如何动态加载这个资源,(如更换R.styleable参考)?
见[访问<声明-设置样式>资源编程](http://stackoverflow.com/questions/13816596/accessing- declare-styleable-resources-programatically)发布或许可以帮助你解决当前问题 – 2013-03-01 22:46:24
太棒了,感谢您的快速回复。这正是我所需要的。如果您发帖作为答案,我会选中它! – ch3rryc0ke 2013-03-01 23:08:00