在CoordinatorLayout上以编程方式隐藏/显示工具栏 [英] Hide/Show Toolbar programmatically on CoordinatorLayout

查看:105
本文介绍了在CoordinatorLayout上以编程方式隐藏/显示工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

滚动我的RecycleView ToolBar隐藏或显示(带有动画)时.

When I scroll my RecycleView ToolBar hide or show (with animation).

如何以编程方式返回ToolBar?

推荐答案

如果工具栏位于可能位于CoordinatorLayout内的AppBarLayout内,则应使用类似的方法.

If your toolbar is inside an AppBarLayout which is probably inside your CoordinatorLayout then something like this should work.

AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBar);
            appBarLayout.setExpanded(true, true);

或者将其折叠

AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBar);
            appBarLayout.setExpanded(false, true);

这是定义

setExpanded(boolean expanded, boolean animate)

请注意,此方法可从支持库的v23中获得,此处为与AppBarLayout的滚动一样,此方法依赖于此布局是CoordinatorLayout的直接子代."希望对您有所帮助!

Take note that this method is available from v23 of the support library, here is some documentation for reference, the key thing to note is "As with AppBarLayout's scrolling, this method relies on this layout being a direct child of a CoordinatorLayout." Hope this helps!

这篇关于在CoordinatorLayout上以编程方式隐藏/显示工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆