How to click in the Toolbar on the navigation button?

not working for me

activity.findViewById(R.string.abc_action_bar_up_description).performClick();

I set in activity

    setSupportActionBar(toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ...
        }
    });

Upvotes: 0

Views: 842

Answers (2)

To make a click on the navigation button which is located in the toolbar you need to do the following:

Add text to the navigation button

toolbar.setNavigationContentDescription("up");

After finding it in the following way

final ArrayList<View> outViews = Lists.newArrayList();
        activity.findViewById(R.id.toolbar).findViewsWithText(outViews, "up", View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
        outViews.get(0).performClick();

Upvotes: 1

You should call your stuff as R.id.yourStuff && check it for android:clickable="true" prameter (if it's not a button).

Upvotes: 0

Related Questions