Anthony,
In general, a background is not necessarily a solid color - it can be an
bitmap, a nine-patch, a gradient, state list, etc.
If you know that you specified a solid color in XML, you could try
casting the Drawable to a ColorDrawable:
http://developer.android.com/reference/android/graphics/drawable/ColorDrawable.html
Additionally, I think you should be able set a tag for the button in
XML, that you would then be able to access from code:
<Button.....
android:tag="@color/your_background_color"
/>
Color color = (Color) button.getTag();
This would come in handy if you ever decide to switch from solid color
backgrounds to something similar but different (a gradient with a
lighting effect, etc.)
-- Kostya
25.01.2011 23:34, Antony BODY пишет:
Hi all,
I'm trying to get the background color of a button. This color was
applied on this button with the XML code.
It's little complicated !!!
I tried some solutions like:
Drawable d = findViewById(R.id.my_btn).getBackground();
But i can't obtain the background color code.
Any people have idea ??
Regards.
--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com
--
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