Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting screen coordinate of action bar menu item for creating introduction screen

I was wondering, if there is any possibility of getting the screen coordinates of an action bar menu item?

As I would like to create an introduction screen, to draw an arrow pointing to the desired action bar menu item, so that the user knows where to start.

enter image description here

like image 324
Cheok Yan Cheng Avatar asked May 19 '13 05:05

Cheok Yan Cheng


2 Answers

Here's how I did it:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(item.getItemId().equals(R.id.my_menu_item)) {
        View menuView = findViewById(R.id.menu_item_search);
        int[] location = new int[2];
        menuView.getLocationOnScreen(location);
        int menuViewX = location[0];
        int menuViewY = location[1];
    }
}
like image 167
penduDev Avatar answered Nov 12 '22 18:11

penduDev


Presently, there is no documented and supported means for doing this, except for your own custom action layouts or action views. There is no API to retrieve ordinary contents of the action bar (home affordance, title, regular items).

ShowcaseView, as mentioned in the other answer, probably does some undocumented/unsupported things for this, such as traversing the View hierarchy to get at these widgets. That's risky, insofar as future versions of Android, or manufacturer/ROM modder changes to Android, may break that logic.

like image 32
CommonsWare Avatar answered Nov 12 '22 18:11

CommonsWare