[android-developers] Re: Introspecting Android style in code
use this method instead
On Saturday, November 23, 2013 6:09:22 PM UTC+2, Y2i wrote:
-- http://developer.android.com/reference/android/content/Context.html#obtainStyledAttributes(int, int[])
On Saturday, November 23, 2013 6:09:22 PM UTC+2, Y2i wrote:
I have a style<style name="MyText"> <item name="android:textColor">#ffff
8080 </item> <item name="android:background">#ffc0c0c0 </item> </style>that I would like to introspect in code. I run this code:final Resources r = getResources(); final TypedArray a = r.obtainTypedArray(R.style.MyT
ext ); try { for (int i=0; i<a.length(); ++i) { final TypedValue v = a.peekValue(i); if (v != null) { Log.d(TAG, "assetCookie: " + v.assetCookie); Log.d(TAG, "changingConfigurations: " + v.changingConfigurations); Log.d(TAG, "data: " + v.data); Log.d(TAG, "density: " + v.density); Log.d(TAG, "resourceId: " + v.resourceId); Log.d(TAG, "string: " + v.string); Log.d(TAG, "type: " + v.type); Log.d(TAG, "---------------------------------" ); } } } finally { a.recycle(); }The output is:D/PlaceholderFragment( 2051): assetCookie: 2 D/PlaceholderFragment( 2051): changingConfigurations: 0 D/PlaceholderFragment( 2051): data: -32640 D/PlaceholderFragment( 2051): density: 0 D/PlaceholderFragment( 2051): resourceId: 0 D/PlaceholderFragment( 2051): string: null D/PlaceholderFragment( 2051): type: 28 D/PlaceholderFragment( 2051): ------------------------------
--- D/PlaceholderFragment( 2051): assetCookie: 2 D/PlaceholderFragment( 2051): changingConfigurations: 0 D/PlaceholderFragment( 2051): data: -4144960 D/PlaceholderFragment( 2051): density: 0 D/PlaceholderFragment( 2051): resourceId: 0 D/PlaceholderFragment( 2051): string: null D/PlaceholderFragment( 2051): type: 28 D/PlaceholderFragment( 2051): --------------------------------- From the output I know the type of the TypedValue and the value it stores. I would also be interested to find out which TypedValue is
android:textColor
and which isandroid:background
. How can I do that?Thank you!
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home