开发者

Finding the value of the reference name to R

I am doing some debugging in my application, mainly loading custom styles from styles.xml when my custom view is given a style="@styles/CustomStyle", and attributes such as custom:attribute="custom value"

I looked into the TextView source to see how Android loads styles/attributes and I am mimicking that. However I am not being passed any of my R.styleables through some of the calls to my constructors and so I am trying to peek in there to see which resources are coming in.

I am using obtainSty开发者_运维知识库ledAttributes() to load these key/value pairs into a TypedArray, however I am wondering if there is an easy way to convert the R.styleable.CustomWidget_customAttribute from the int that R reads, to its referenced name.

In essence, I want LogCat to say, "We've been given R.styleable.xxx" and not "We've been given 1487214712442"


Look at this method: http://developer.android.com/reference/android/content/res/Resources.html#getResourceName(int)

Return the full name for a given resource identifier. This name is a single string of the form "package:type/entry".


You most likely are not able to do this explicitly, as all resources are stored in a generated java class with no accessible reference to the original strings.

However, your best bet is override the toString() method for the R class.

See if something like that works.

Hope this helped!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜