Reputation:
I use ShowcaseView like this:
ActionItemTarget target = new ActionItemTarget(this, R.id.menu_search);
ShowcaseView sv = new ShowcaseView.Builder(this, true)
.setTarget(target)
.setContentText("Press this to search")
.setStyle(R.style.CustomShowcaseTheme)
.build();
But when I start app the first, ShowcaseView highlights home button. When I try to start app again, correct ActionBar item is showcased. My app doesn't use compatibility libraries like ActionbarSherlock.
Any idea why this may be happening?
Upvotes: 2
Views: 570
Reputation: 683
I will try to present sample code here:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
new ShowcaseView.Builder(this)
.withMaterialShowcase()
.setTarget(new ToolbarActionItemTarget(this.toolbar, R.id.menu_search))
.setContentText("Here's how to highlight items on a toolbar")
.build()
.show();
return true;
}
Note: toolbar declare as member of the class.
Upvotes: 0
Reputation: 20500
As requested:
The problem is that you are trying to retrieve an id for a view that is not in the hierarchy yet. According to the activity view cycle the menu is only created after onCreate
. The best solution is to use onCreateOptionsMenu
but even here R.id.menu_search
will not return a valid id because the menu hasn't been created yet. Since the order of events has changed in API lvl 16 I suggest you hack it a little bit. You can create a handler on your onCreate()
and execute a postDelayed runable. The code will be executed after the menu has been designed. On that runable you can retrieve the view for R.id.menu_search
and highlight it.
Upvotes: 3