Android get a View reference to action bar item?
<p>I'm using <a href="https://github.com/deano2390/MaterialShowcaseView" rel="nofollow noreferrer">MaterialShowcaseView</a> to show the user a quick tutorial, when they first start the app.</p>

<p>The problem I'm having is that I'm only able to get a view reference to the items in my action bar items when the user selects that item in onOptionsItemSelected.</p>

<p>i.e.</p>

<pre><code>@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.my_location:
            // User chose the "Favorite" action, mark the current item
            // as a favorite...
            ShowcaseConfig config = new ShowcaseConfig();
            config.setDelay(500); // half second between each showcase view


            MaterialShowcaseSequence sequence = new MaterialShowcaseSequence(this, SHOWCASE_ID);

            sequence.setConfig(config);

            sequence.addSequenceItem(findViewById(R.id.action_my_location),
                    "This is button one", "GOT IT");
            sequence.start();
            Toast.makeText(MapsActivity.this, "My location action press", Toast.LENGTH_SHORT).show();

            return true;

        default:
            // If we got here, the user's action was not recognized.
            // Invoke the superclass to handle it.
            return super.onOptionsItemSelected(item);
    }
}
</code></pre>

<p>The above code works.</p>

<p>Is it possible to get a view reference in onCreateOptionsMenu? Everything else I've tried gives me a null object reference for the view.</p>

<p>I've tried <a href="https://stackoverflow.com/a/9529346/966825">this answer</a> too, to no success. </p>

<p>I should mention that for the actionBar I used android's <a href="http://developer.android.com/training/appbar/setting-up.html" rel="nofollow noreferrer">action bar tutorial</a>.</p>

<p>Thanks guys.</p>

<p>EDIT:</p>

<p>This is what I've tried to do now:</p>

<pre><code>@Override
    public void invalidateOptionsMenu() {
        super.invalidateOptionsMenu();

    }
    MenuItem mi;
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        mi = menu.findItem(R.id.action_my_location);
        new MaterialShowcaseView.Builder(this)
                .setTarget(mi.getActionView())
                .setDismissText("GOT IT")
                .setContentText("This is some amazing feature you should know about")
                .setDelay(300) // optional but starting animations immediately in onCreate can make them choppy
                .singleUse("101010110") // provide a unique ID used to ensure it is only shown once
                .show();
        return super.onPrepareOptionsMenu(menu);
}
</code></pre>

<p>Error:                                                                          </p>

<blockquote>
  <p>java.lang.NullPointerException: Attempt to invoke virtual method 'void
  android.view.View.getLocationInWindow(int[])' on a null object
  reference</p>
</blockquote>