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.
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];
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With