0

First, I'm implementing this using support-library v7's AppCompat, not native 3.0+.

Short form: What style/code/listener/etc. can I invoke to make a click on my ActionView look like a plain old ActionButton?

Background:

I'm building a shopping app and have decided to implement a "cart" icon in the Action Bar using a composite ImageView + TextView approach. The Image shows a cart, and the text overlaid on top of it shows how many items are in the cart. Because the cart contents count changes dynamically, I am unable to use a standard ActionButton / icon.

However, unlike the demo use for ActionView's, e.g. (http://developer.android.com/guide/topics/ui/actionbar.html#ActionView) involving ProgressBar's or SearchView's, I really want to treat this ActionView just like it was another ActionButton.

I know I can add a custom click listener and flash the ActionView to respond to the click, but I'm looking for best practice on making the click experience look and feel just like clicks to regular ActionButton's. For instance, on my device finger-downing on an ActionButton highlights the background blue, and stays blue until up; but I'm not sure if the color is the same across devices, or if its subject to change in the future, etc.

I tried setting

style="@style/Widget.AppCompat.Light.ActionButton"

in my ActionView's custom @layout file's root RelativeLayout, but that didn't do anything.

jdowdell
  • 1,578
  • 12
  • 24

1 Answers1

3

Thanks mostly to @DaveClemmer's answer in ImageButton doesn't highlight on click with Transparent background

I found a simple edit. In my ActionView's @layout file's root RelativeLayout I just added:

android:background="?attr/selectableItemBackground"
android:clickable="true"

(I got away with the attr line because I have support library v7 in use, ala (android - apply selectableItemBackground in xml with support v7))

Community
  • 1
  • 1
jdowdell
  • 1,578
  • 12
  • 24