How can I get the location of an icon in the action menu?
<p>I am developing a tutorial for an application and I need to point at a particular icon in the toolbar.</p>

<p>Here is an extract of the XML for the action menu:</p>

<pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"&gt;

&lt;item android:id="@+id/AbErase"
    android:title="@string/Erase"
    android:icon="@android:drawable/ic_delete"
    android:orderInCategory="10"
    app:showAsAction="ifRoom|collapseActionView" /&gt;

&lt;item android:id="@+id/AbSuggest"
    android:title="@string/Suggest"
    android:icon="@mipmap/ic_lightbulb_outline_white_48dp"
    android:orderInCategory="50"
    app:showAsAction="ifRoom|collapseActionView" /&gt;
&lt;item android:id="@+id/AbUndo"
    android:title="@string/ActionBarUndo"
    android:icon="@android:drawable/ic_menu_revert"
    android:orderInCategory="51"
    app:showAsAction="ifRoom|collapseActionView" /&gt;
...
</code></pre>

<p>Here is my code:</p>

<pre><code>@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    isBeingRestored = (savedInstanceState != null);

    Toolbar scToolbar = (Toolbar) findViewById(R.id.Sc_toolbar);
    setSupportActionBar(scToolbar);

    scToolbar.post(new Runnable() {
        @Override
        public void run() {
            if (!isBeingRestored) {
                //View mErase = findViewById(R.id.AbErase);
                View mErase = overflowMenu.getItem(0).getActionView();
                int[] location = new int[2];
                mErase.getLocationOnScreen(location);
                eraseIconLeft = location[0];
            }
        }
    }
</code></pre>

<p>With <code>View mErase = findViewById(R.id.AbErase);</code> <code>mErase</code> is set to <code>null</code>, **** <strong>start EDIT</strong> **** which is not suprising as AbErase is the id of a MenuItem, not the id of a View. **** <strong>end EDIT</strong> ****
With <code>View mErase = overflowMenu.getItem(0).getActionView();</code> <code>location</code> is set to (0, 24), which is wrong as there already is a logo icon and a title in the toolbar.</p>

<p>How can I get the absolute X coordinate of the <code>AbErase</code> view in the toolbar?</p>

<p>**** <strong>EDIT</strong> ****
here is the code where the initialisation of the static variable <code>overflowMenu</code> can be found:</p>

<pre><code>@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    actionBar.collapseActionView();

    overflowMenu = menu;

    isInitializedMenuItem = menu.findItem(R.id.AbInitialized);
    isInitializedMenuItem.setChecked(isInitializeCbxChecked);

    return super.onCreateOptionsMenu(menu);
}
</code></pre>