1

Is there a way that you can get actionbar views as object references. For instance I would like to get the overflow view in order to know the coordinates on the screen. currently I have manage an ugly solution which is. Get a menu item with an id

overflowView =((ViewGroup)parent.findViewById(R.id.menu_id).getParent()).getChildAt(2);

Necronet
  • 6,704
  • 9
  • 49
  • 89
  • Did you really manage with this piece of code? I can't find a menu item by id (NPE). What is `parent` in your example? – Michał Klimczak Sep 01 '12 at 13:15
  • sorry to clarify 'parent' refer to the parent activity because this was inside a TabActivity so you don't need parent if you are in a plain Activity – Necronet Sep 01 '12 at 20:24

1 Answers1

1

Is there a way that you can get actionbar views as object references.

Only the ones you create yourself, via android:actionLayout and kin.

For instance I would like to get the overflow view in order to know the coordinates on the screen.

Your solution is unlikely to remain stable across Android versions. It may or may not work on ActionBarSherlock. I would recommend that you find some other solution for whatever you perceive your problem to be that does not involve messing around with the internals of the ActionBar implementation.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Yes I am aware of that, and I was afraid that be the answered. and actionLayout it does not apply very much with overflow. I used sherlock but changed the code in a way to assign the overflow an Id so for sherlock AB implementation is actually simpler to do that. – Necronet Jul 05 '12 at 14:57
  • @Necronet: What specifically are you trying to do with the overflow? – CommonsWare Jul 05 '12 at 14:58
  • trying to get the coordinates of the overflow to animate something over there. any suggestion? – Necronet Jul 05 '12 at 14:59
  • @Necronet: Get rid of the animation. :-) – CommonsWare Jul 05 '12 at 15:14
  • 1
    @Necronet: For starters, because the animation value is unlikely to be worth the maintenance cost of dealing with all the places where your code will break. Bear in mind that any device manufacturer can change the inner workings of `ActionBar`, as well as Google. Not to mention that they can change the size of things (e.g., font scale), and so forth. – CommonsWare Jul 05 '12 at 15:49