Yeah the documentation is really sub-par on this area. I want to write up some more, but I've been wanting to do that for 2 years now. :/
On Sun, Jan 16, 2011 at 5:35 PM, Zsolt Vasvari <zvasv...@gmail.com> wrote: > This is a bit off-topic, but perhaphs not so much: > > The single most confusing aspect of the Android platform, in my > opinion, this whole business with Themes/Styles/Stylable/Attributes. > Does anybody have a link to a good write-up on how this really works? > I know it's in the docs, but I find it a bit hard to follow. > > > > On Jan 17, 4:39 am, Dianne Hackborn <hack...@android.com> wrote: > > textSize is not defined in the platform's base theme. > > > > These are the text size-related attributes in the theme: > > > > <!-- Default appearance of text: color, typeface, size, and > > style. --> > > > > <attr name="textAppearance" format="reference" /> > > > > <!-- Default appearance of text against an inverted background: > > > > color, typeface, size, and style. --> > > > > <attr name="textAppearanceInverse" format="reference" /> > > > > <!-- Text color, typeface, size, and style for "large" text. > > Defaults to primary text color. --> > > > > <attr name="textAppearanceLarge" format="reference" /> > > > > <!-- Text color, typeface, size, and style for "medium" text. > > Defaults to primary text color. --> > > > > <attr name="textAppearanceMedium" format="reference" /> > > > > <!-- Text color, typeface, size, and style for "small" text. > > Defaults to secondary text color. --> > > > > <attr name="textAppearanceSmall" format="reference" /> > > > > <!-- Text color, typeface, size, and style for "large" inverse > text. > > Defaults to primary inverse text color. --> > > > > <attr name="textAppearanceLargeInverse" format="reference" /> > > > > <!-- Text color, typeface, size, and style for "medium" inverse > > text. Defaults to primary inverse text color. --> > > > > <attr name="textAppearanceMediumInverse" format="reference" /> > > > > <!-- Text color, typeface, size, and style for "small" inverse > text. > > Defaults to secondary inverse text color. --> > > > > <attr name="textAppearanceSmallInverse" format="reference" /> > > > > So the textSize attribute is rarely set as part of the base platform, > except > > inside of a TextAppearance style: > > > > http://developer.android.com/reference/android/R.styleable.html#TextA... > > > > So generally I wouldn't expect that code to work, unless textSize has > been > > explicitly supplied by you in a theme. Instead, you need to retrieve the > > resource of the TextAppearance size you want, and then can retrieve the > > textSize from that. > > > > That said, what *should* happen is you just get the default value you > passed > > in, because the theme doesn't hold its own value. You should never get a > > crash. The obtainStyledAttributes() method is supposed to build an array > of > > values that corresponds to the array you passed in to it. So a crash > like > > this is completely independent of whatever is defined in the theme, and > just > > an outright bug in whatever platform code it is running on. > > > > Also your code has another issue where it is using array.getResourceId() > -- > > once you do get down to the TextAppearance, generally the values there > are > > literals, not references to other resources. So this also will always > fail > > (it doesn't have a resource id), even if textSize does have a value, > again > > resulting in you getting your default value. You should just call > > getDimensionPixelSize() with the array offset at which you want to > retrieve > > your value -- 0 in your case. > > > > Oh. > > > > That is probably the crash. :) If for some reason there *is* some value > for > > textSize, if getResourceId() returns non-0, then you will pass a value > > 0 > > to getDimensionPixelSize(), which is outside the array you originally > passed > > in. > > > > > > > > > > > > On Sun, Jan 16, 2011 at 9:24 AM, Brill Pappin <br...@pappin.ca> wrote: > > > I'm getting this exception: > > > > > java.lang.ArrayIndexOutOfBoundsException > > > at > > > > android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:455) > > > > > from this code: > > > > > TypedArray array = > context.getTheme().obtainStyledAttributes(style, > > > new int[] { android.R.attr.textSize }); > > > > > int textSize = array.getDimensionPixelSize(array.getResourceId(0, 0), > > > defValue); > > > > > I'm expecting a standard value from the system since thats what I'm > asking > > > for. > > > > > It actually works on all devices I can get my hands on and of course > the > > > error reporting doesn't tell me anything useful except a stack trace. > > > > > Does anyone have a solution that might work instead of this one? > > > > > Does anyone know what device this might be? > > > > > I do know that it has to be a 2.2 device or better because I've made > the > > > minimum 2.2 (froyo) > > > > > At the moment the only idea I can come up with is to simply send a > static > > > value, but I'm obviously going to have to guess what the device is. > > > > > -- > > > 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+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> > <android-developers%2BunsubsÂcr...@googlegroups.com> > > > For more options, visit this group at > > >http://groups.google.com/group/android-developers?hl=en > > > > -- > > Dianne Hackborn > > Android framework engineer > > hack...@android.com > > > > Note: please don't send private questions to me, as I don't have time to > > provide private support, and so won't reply to such e-mails. All such > > questions should be posted on public forums, where I and others can see > and > > answer them.- Hide quoted text - > > > > - Show quoted text - > > -- > 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+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en