简体   繁体   中英

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) {
            ...
        }
    });

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();

您应该将您的东西称为R.id.yourStuff &&检查是否为android:clickable="true" (如果不是按钮)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM