andbook!.pdf - Learning Android Get an anddev.org - Android-Shirt Back to index
anddev.org Header Logo
FAQ Search Top rated articles Browse Feeds anddev.org - Authors Contact Details Register Log in

[Solved] Custom Button Colors...


 
       anddev.org - Android Development Community | Android Tutorials | Index -> Other Coding-Problems
Author Message
aetmos
Junior Developer


Joined: 18 Jan 2008
Posts: 21

PostPosted: Tue Feb 19, 2008 11:44 am    Post subject: [Solved] Custom Button Colors... Reply with quote

Hi Plusminus,

Would you mind expanding upon your comments regarding modifying the highlight colors of a button here:

http://groups.google.com/group/android-developers/browse_thread/thread/62e95582838f680a/13b3e8eaf38d45e7?lnk=gst&q=color#13b3e8eaf38d45e7

I've read this page, but I just don't see how I can use this to modify the button highlight colors. I just want something other than the horribly ugly orange that is the default of the new SDK. Any help would be greatly appreciated.

Thanks,
Tom
Back to top
View user's profile Send private message
plusminus
Site Admin


Joined: 14 Nov 2007
Posts: 2067
Location: Germany

PostPosted: Tue Feb 19, 2008 4:29 pm    Post subject: Reply with quote

Hello aetmos,

I haven't done that tutorial my self, it was created by benderamp, but I would start here:
Java:
    /** Return an array of resource IDs of
      * the Drawable states representing the
      * current state of the view. */

     @Override
     protected int[] onCreateDrawableState(int arg0) {


Here we very probably have to return our custom custom "nine-patch"-images.
Arrow http://code.google.com/android/reference/available-resources.html#ninepatch

Regards,
plusminus

_________________

| Android Development Community / Tutorials
Back to top
View user's profile Send private message Send e-mail Visit poster's website
aetmos
Junior Developer


Joined: 18 Jan 2008
Posts: 21

PostPosted: Wed Feb 20, 2008 7:03 pm    Post subject: Reply with quote

Thanks for your help, Plusminus. After doing some digging, it looks like that the returned array holds references to "states", not drawables. For instance, when the button is focused/orange, onCreateDrawableState is returning this array: {0x101016E,0x101016F,0x1010170}. When the button isn't focused/orange, it's returning this: {0x101016F,0x1010170}. By decompiling Android's R.class, it looks like these resources are:

0x101016E: state_focused
0x101016F: state_window_focused
0x1010170: state_enabled

So, unfortunately, I still don't know where the image resources are being referenced, or how to change them...I wonder why they picked orange of all colors...

Tom
Back to top
View user's profile Send private message
aetmos
Junior Developer


Joined: 18 Jan 2008
Posts: 21

PostPosted: Wed Feb 20, 2008 8:39 pm    Post subject: Reply with quote

SOLVED!!!!

Okay, so it's not necessary to create a custom view. The rather simple solution is posted here:

http://groups.google.com/group/android-developers/browse_thread/thread/1906f24707594f67/0714e077e25d63a6?lnk=gst&q=button#0714e077e25d63a6

Quote:
In res/drawable, create a file called for instance mybutton_background.xml
and put something like this inside:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false"
android:drawable="@drawable/button_background_focus" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/button_background_pressed" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/button_background_pressed" />
<item android:drawable="@drawable/button_background_normal" />
</selector>

Then set this drawable as the background of your button with
android:background="@drawable/mybutton_background"


Thanks,
Tom
Back to top
View user's profile Send private message
Display posts from previous:   
       anddev.org - Android Development Community | Android Tutorials | Index -> Other Coding-Problems All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


© 2007, Android Development Community
All rights reserved.
Powered by phpBB.