3

I'm developing an app for ICS. I like the way in which buttons in action bar feedbacks to user's touch (blue glow around), is there some simple way to add the same feedback for ImageButton?

Something like this, but with ImageButton: enter image description here

TZHX
  • 5,291
  • 15
  • 47
  • 56
user1049280
  • 5,176
  • 8
  • 35
  • 52

3 Answers3

2

Yes, go into your SDK.

Navigate to Platforms->android-15->data->res

You are now in the res folder for the system. If you hunt in the drawable folder you should be able to find the xml selector that represents the default system button. That selector should make reference to some images that are stored in the other drawable folders. Pick a resolution and go into its folder and find all of the required images.

Once you've got all the required resources you can include them in your own project. Then use your own selector to show the alternate image when it is pressed.

Im not certain the effect you are after but I think if you set btn_default_holo_pressed.9.png as the background of an image view with an image in the src it should appear with the blue bar around the outside of it. With the selector you can make this happen during the press action.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
1

If you are just trying to add feedback

Use the drawable as the ImageButton background.

    <ImageButton
        android:id="@+id/btn_show_filter_dialog"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:background="@drawable/ic_filter_state"/>

Create the drawable file for your Image button:

ic_filter_state.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_enabled="false"
        android:drawable="@drawable/ic_filter_disable" />
    <item
        android:state_pressed="true"
        android:state_enabled="true"
        android:drawable="@drawable/ic_filter_click" />
    <item
        android:state_focused="true"
        android:state_enabled="true"
        android:drawable="@drawable/ic_filter_roll" />
    <item
        android:state_enabled="true"
        android:drawable="@drawable/ic_filter_solid" />
</selector>

For feedback, you will only really need state_pressed="true" and state_enabled="true" drawables

Here is an example with a vector drawable, but you can add your own drawable. Change the fillColor column for each state:

ic_filter_solid.xml:

<vector android:alpha="1" android:height="24dp"
    android:viewportHeight="512" android:viewportWidth="512"
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#ffffff" android:pathData="M487.976,0H24.028C2.71,0 -8.047,25.866 7.058,40.971L192,225.941V432c0,7.831 3.821,15.17 10.237,19.662l80,55.98C298.02,518.69 320,507.493 320,487.98V225.941l184.947,-184.97C520.021,25.896 509.338,0 487.976,0z"/>
</vector>
live-love
  • 48,840
  • 22
  • 240
  • 204
0

I think this might be what you're looking for: Image in Canvas with touch events

Imagebuttons and imageviews are pretty much similar to each other.

Community
  • 1
  • 1
Chikilah
  • 490
  • 2
  • 8