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

我的未来我决定 提交于 2019-12-09 10:44:53

问题


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.


回答1:


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];
    }
}



回答2:


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.



来源:https://stackoverflow.com/questions/16631806/getting-screen-coordinate-of-action-bar-menu-item-for-creating-introduction-scre

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!