0

I'm using TapTargetView to create my Showcase and it's working nice to buttons and the toolbar, but I need to target my Navigation Drawer menu and I'm not getting there.

One of my aproaches was to create a local variable TextView (or anything else) and use app:actionViewClass on my menu item. The target is reached but not like expected, because the actionViewClass is on the right margin of the menu item look the screenshot

<item
    android:id="@+id/nav_criar_projeto"
    android:icon="@drawable/ic_add"
    android:title="@string/criar_projeto"
    app:showAsAction="always"
    app:actionViewClass="android.widget.TextView" />
TapTarget.forView(
  navigationView.getMenu().findItem(R.id.nav_criar_projeto).getActionView(),
     "Vamos criar nosso primeiro projeto",
     "Você ainda não possui um projeto, vamos criar um")

Is it possible to target the icon or the text of this menu item?

Renan Ceratto
  • 130
  • 2
  • 12
  • I'm not familiar with how `TapTargetView` works, exactly, but one way to get that menu item's main `View` is to set an `app:contentDescription` on the ``, then call `findViewsWithText(outList, desc, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION)` on the `NavigationView` to get an `ArrayList` of `View`s with that description. If it's unique in the `NavigationView`, you should be good; i.e., it should be `outList`'s only element. – Mike M. Aug 21 '19 at 13:56
  • Thanks Mike, but it seams not to work for one reason: my NavigationView is modifyed at runtime, and the menu I need is one of this that is inflated. When I search for one of the pre existing item, the result contains 1 view, but its null for the one I need. Maybe I need to execute on a listener after the menu is fully loaded – Renan Ceratto Aug 21 '19 at 14:46
  • Oh, there's `View.FIND_VIEWS_WITH_TEXT`, too, that you can use with the title. Sorry, I'm just so used to doing the content description trick, when multiple `View`s have the same text. – Mike M. Aug 21 '19 at 14:53
  • Worked! But just after calling the method using `new Handler().post()` – Renan Ceratto Aug 21 '19 at 15:12
  • Oh, is that what you meant about the listener for after loading? Yeah, you'd have to give it a chance to add and layout. Cool. Glad you got it working. Cheers! – Mike M. Aug 21 '19 at 15:15
  • If you want, write as an answer so I can accept – Renan Ceratto Aug 21 '19 at 16:26
  • Oh, I'm good. :-) Please feel free to post an answer with your final setup. This will be a good link in the future for others with the same question. Thank you, though. I appreciate the offer. Cheers! – Mike M. Aug 21 '19 at 16:29

1 Answers1

0

Solved this by setting app:contentDescription="name_here" to my <item> inside the <menu> Then just call

navigationView.findViewsWithText(menuItems, "name_here", View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);

But to work properly, the code above need to be called on a new thread, so the interface have enough time to render.

new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        methodToFindTheView();
                    }
                });
Renan Ceratto
  • 130
  • 2
  • 12