[Solved] Custom Button Colors...

Put your problem here if it does not fit any of the other categories.

[Solved] Custom Button Colors...

Postby aetmos » Tue Feb 19, 2008 11:44 am

Hi Plusminus,

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

http://groups.google.com/group/android- ... eaf38d45e7

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
aetmos
Junior Developer
Junior Developer
 
Posts: 21
Joined: Fri Jan 18, 2008 12:33 am

Top

Postby plusminus » Tue Feb 19, 2008 4:29 pm

Hello aetmos,

I haven't done that tutorial my self, it was created by benderamp, but I would start here:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.      /** Return an array of resource IDs of
  2.       * the Drawable states representing the
  3.       * current state of the view. */
  4.      @Override
  5.      protected int[] onCreateDrawableState(int arg0) {
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Here we very probably have to return our custom custom "nine-patch"-images.
:arrow: http://code.google.com/android/referenc ... #ninepatch

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby aetmos » Wed Feb 20, 2008 7:03 pm

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
aetmos
Junior Developer
Junior Developer
 
Posts: 21
Joined: Fri Jan 18, 2008 12:33 am

Postby aetmos » Wed Feb 20, 2008 8:39 pm

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- ... 77e25d63a6

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
aetmos
Junior Developer
Junior Developer
 
Posts: 21
Joined: Fri Jan 18, 2008 12:33 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 16 guests