简体   繁体   English

如何在导航按钮上单击工具栏?

[英]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" (如果不是按钮)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android如何使用工具栏中的按钮切换以使用片段打开/关闭导航抽屉 - Android how toggle with the button in toolbar to open/close navigation drawer with Fragments 如何部分禁用单击 Android 工具栏中的主页按钮? - How to partially disable click on home button in Android toolbar? 如何使用导航组件隐藏图标并仅在工具栏中显示后退按钮? - How to hide the icons and only show the back button in the toolbar using navigation component? 如何在Android工具栏导航图标中设置复选框? - How to set an checkbox in the Android toolbar navigation icon? 如何在Android工具栏下方设置导航抽屉? - How to set the Navigation Drawer below the toolbar in Android? 如何将导航抽屉切换添加到工具栏 - How to add navigation drawer toggle to a toolbar 不要将工具栏连接到导航抽屉怎么办? - Do not connect toolbar to navigation drawer how to do it? 如何使工具栏中的按钮居中 Android - How to center button in toolbar Android 将工具栏主导航按钮设置为跟随Backstack,Android - Set Toolbar Home Navigation Button to Follow backstack, Android 在android中管理工具栏的导航和从片段到片段的后退按钮 - Manage toolbar's navigation and back button from fragment to fragment in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM