03.08.2012 3:00 пользователь "Spiral123" <[email protected]> написал: > > Thanks Kostya, > > it looks like Widget.TextView.PopupMenu leads to textColorPrimaryDisableOnly.
It does in the stock platform, but not necessarily on other devices. It could be @color/your_eyes_will_bleed_from_this_magenta on some especially colorful one :) If I try to read the value of this using the code: > >>> TypedValue value = new TypedValue(); >>> >>> getTheme().resolveAttribute(android.R.attr.textColorPrimaryDisableOnly, value, true); >>> >>> >>> int menuTextColor = getResources().getColor(value.resourceId); > > > I get the same value if I try a Samsung phone or an HTC phone (which have white and black option menu backgrounds). Of course you do - you're reading the value of textColorPrimaryDisableOnly attribute from the activity's theme. Try getting the textAppeareance attribute from the style (name spelled out below), not from the theme. > > I think the menu_background_fill_parent_width leads to a 9-patch png and I'm not sure which pixel to pull out of it and how to do that in order to read its color. That would be my plan B. Isn't there some sort of getPixelColor on a nine patch drawable? If not, try rendering it to a canvas and reading a pixel value from there. Again, you will want to get this drawable from the style - a manufacturer could keep the original drawable in place, add a new one, and change the reference (style attribute). > > > On Thursday, August 2, 2012 4:35:16 PM UTC-4, Kostya Vasilyev wrote: >> >> Take look in the platform's styles.xml and themes.xml. >> >> These sound somewhat promising: >> >> <style name="Widget.TextView.PopupMenu"> >> <item name="android:clickable">true</item> >> <item name="android:textAppearance">@style/TextAppearance.Widget.TextView.PopupMenu</item> >> </style> >> >> <style name="Widget.PopupMenu" parent="Widget.ListPopupWindow"> >> </style> >> >> Looking in PhoneWindow.java (in the framework, under base/policy/src/...) should be useful too - the "legacy" (pre-action bar) menu implementation is here. >> >> And.... I just looked there myself, and it looks like the code uses this attribute from the current theme: >> >> <item name="panelFullBackground">@android:drawable/menu_background_fill_parent_width</item> >> >> ... and so it makes sense that this attribute has the same value (as above) in the legacy and both Holo themes (I've got 4.1.1 sources open right now). >> >> -- K >> >> 2012/8/3 Spiral123 >>> >>> Hi all... >>> >>> Scratching my head here, need some help. >>> >>> I'm trying to read the option menu text color for the running device. I'm not interested in trying to override the system menu behavior or anything funky, my theory is that if I know what color the text is (or the menu item background) then I will be able to display a custom dark or light menu icon set for my options depending on how the manufacturer has themed the option menu on their particular device. >>> >>> I don't mind if I need to look internally to source variables as I'm only interested in getting this for the 2.2 and 2.3 platforms: 2.1 and below is not targeted and I'm not interested in displaying icons in the 3.0 overflow menu. If I know how to get the value I can make sure that my code won't break regardless of platform. >>> >>> Anyone been down this road before? >>> >>> Nick >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Android Developers" group. >>> To post to this group, send email to [email protected] >>> To unsubscribe from this group, send email to >>> [email protected] >>> 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 post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > 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 post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

