ShowcaseView
ShowcaseView copied to clipboard
NavigationView menu item targeting
Hi, the NavigationView inflates its menu from XML similiar to ActionBars/Toolbars. To target a special menu item with SCV, you would probably start using ActionItemTarget. However, the ActionItemTarget only looks for menu items in the ActionBar. I've tried getting the View for a menu entry (e.g. the TextView), but I have not find a way to do so, yet. I will keep you updated with my progress.
:+1: I will have an investigate too, it may require a similar method to the ToolbarActionItemView in the sample
https://github.com/amlcurran/ShowcaseView/blob/master/sample/src/main/java/com/github/amlcurran/showcaseview/sample/ToolbarActionItemTarget.java
Here is my progress.
The menu from NavigationView is inflated when onCreateOptionsMenu is called, equal to ActionBar/ToolBar menus. So you can query its childs afterwards. However, findViewById will not work, as the MenuItemViews all get assigned -1 as id. So you must know the index of the menu you want to showcase:
NavigationMenuView navView = (NavigationMenuView) navigationView.getChildAt(0);
ViewTarget target = new ViewTarget(navView.getChildAt(1));
@Burtan - Awesome progress. navView.getChildAt(1) will return NavigationMenuView. How do you plan to get view of the menuitem you want?
You have to use
navView.getChildAt(i));
to get the specific View you want to showcase. However, the childs also include the header and all other views added to the NavigationView. Thus you have to kinda trial and error which position is the view you want. You could also loop throw all childs and check for the first NavigationMenuItemView. I could imagine that the menuitemviews are clustered and not interrupted by any other views.
Something like this (not tested)
int itemViewsStartingPosition = 0;
for (int i = 0; i < navView.getChildCount(); i++) {
if (navView.getChildAt(i) instanceof NavigationMenuItemView) {
itemViewsStartingPosition = i;
break;
}
}
Yeah unfortunately NavigationView has no external API (what a surprise...), so this isn't currently possible in any other way from @Burtan's example above. Will raise an issue with Google, and post it here
it works. if you use handmaded drawer, use
ViewTarget target = new ViewTarget(mDrawerList.getChildAt(i));
still nothing?