Thursday, August 30, 2012

Re: [android-developers] button change onClick

Please refer at url
http://developer.android.com/guide/topics/ui/controls/button.html:

I copied from that location for you:

Custom background

If you want to truly redefine the appearance of your button, you can
specify a custom background. Instead of supplying a simple bitmap or
color, however, your background should be a state list resource that
changes appearance depending on the button's current state.

You can define the state list in an XML file that defines three
different images or colors to use for the different button states.

To create a state list drawable for your button background:

Create three bitmaps for the button background that represent the
default, pressed, and focused button states.
To ensure that your images fit buttons of various sizes, create the
bitmaps as Nine-patch bitmaps.
Place the bitmaps into the res/drawable/ directory of your project. Be
sure each bitmap is named properly to reflect the button state that they
each represent, such as button_default.9.png, button_pressed.9.png, and
button_focused.9.png.
Create a new XML file in the res/drawable/ directory (name it something
like button_custom.xml). Insert the following XML:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_pressed"
android:state_pressed="true" />
<item android:drawable="@drawable/button_focused"
android:state_focused="true" />
<item android:drawable="@drawable/button_default" />
</selector>
This defines a single drawable resource, which will change its image
based on the current state of the button.
The first <item> defines the bitmap to use when the button is pressed
(activated).
The second <item> defines the bitmap to use when the button is focused
(when the button is highlighted using the trackball or directional pad).
The third <item> defines the bitmap to use when the button is in the
default state (it's neither pressed nor focused).
Note: The order of the <item> elements is important. When this drawable
is referenced, the <item> elements are traversed in-order to determine
which one is appropriate for the current button state. Because the
default bitmap is last, it is only applied when the conditions
android:state_pressed and android:state_focused have both evaluated as
false.
This XML file now represents a single drawable resource and when
referenced by a Button for its background, the image displayed will
change based on these three states.

Best regards,
Liem.V
On 8/31/12 12:47 AM, oriolmesia wrote:
> Hi guys, I have an issue with the final tweak of my new app.
>
> Now that I'm nearly to finish I'm looking to improve my interface.
> What I want it's just to see how my buttons change when someone
> pressed on them, only for the amount of time that the
> button remain pressed.
>
> The buttons on my app are image buttons with some text situated on them.
>
>
> The only way to do that it's to change the button image or the text
> over the button? What kind of event I need to use, onClick method here
> it's useless?
>
>
>
> Thank you for your help,
>
>
>
> Oriol
> --
> 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+unsubscribe@googlegroups.com
> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment