CoordinatorLayout显示隐藏ToolBar
来源:互联网 发布:死侍 知乎 编辑:程序博客网 时间:2024/05/17 07:59
转载:http://blog.csdn.net/android_zhengyongbo/article/details/70140850
刚开始弄得时候在网上找了好多博客,但是因为小编对material不甚了解,所以及时有参考还是走了很多弯路,特此记录一下,先上代码:
1.布局文件
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/coordinator_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> <TextView android:id="@+id/toolBar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="#30469b" app:layout_scrollFlags="scroll|enterAlways" /> </android.support.design.widget.AppBarLayout> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> </android.support.v7.widget.RecyclerView></android.support.design.widget.CoordinatorLayout>
首先CoordinatorLayout作为父节点,AppBarLayout包裹需要滑动显示隐藏的ToolBar,因为小编不擅长使用系统的ToolBar,所以写了一个控件TextView模拟ToolBar。下面添加一个可以滑动的视图,可以是RecyclerView,NestedScrollView(注意ListView的朋友这里使用listView实现滑动是无法显示隐藏ToolBar的,GridView估计也不行,具体原因小编也不清楚,小编就因为这个原因走了好多弯路)。
下面是最重要的
1.在AppBarLayout中加入一下代码:android:fitsSystemWindows="true"--------------------------------2.在TextView中加入以下代码: app:layout_scrollFlags="scroll|enterAlways"-------------------------------------------3.添加滚动视图(例如RecyclerView,NestedScrollView)并且添加以下代码:app:layout_behavior="@string/appbar_scrolling_view_behavior"----------------------------------------------------------
ok,现在滑动滚动视图就可以实现ToolBar的显示隐藏了。
1 0
- CoordinatorLayout显示隐藏ToolBar
- CoordinatorLayout隐藏ToolBar
- android 控件 隐藏toolbar-(CoordinatorLayout Toolbar AppbarLayout)
- CoordinatorLayout和AppBarLayout实现上滑隐藏Toolbar,下滑显示Toolbar
- RecyclerView上拉隐藏Toolbar,下拉显示 CoordinatorLayout官方提供方式
- CoordinatorLayout 与ToolBar 和Fab实现滑动隐藏和显示的学习笔记
- CoordinatorLayout + AppBarLayout实现滑动隐藏ToolBar
- Material Design之CoordinatorLayout+AppBarLayout实现上滑隐藏ToolBar
- CoordinatorLayout实现上滑隐藏ToolBar遇到的问题
- Material Design 之 CoordinatorLayout + AppBarLayout 实现上滑隐藏ToolBar
- Android CoordinatorLayout + AppBarLayout+ToolBar(向上滚动隐藏指定的View)
- Material Design之CoordinatorLayout+AppBarLayout实现上滑隐藏ToolBar
- RecyclerView 滑动隐藏,显示ToolBar
- 实战CoordinatorLayout+Toolbar,CoordinatorLayout+CollapsingToolbarLayout
- CoordinatorLayout、Toolbar、TabLayout、AppBarLayout和RecyclerView组合可以滑动收起或显示Toolbar的demo
- CoordinatorLayout + AppBarLayout + ToolBar
- CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout+Toolbar
- easyui toolbar 动态显示与隐藏
- 判断回文字符串(给定开始位置和字符个数)
- 文章标题
- POJ 1939 Diplomatic License G++
- Spring @Autowired和@Qualifier注解
- 关于springmvc返回到前台报406错误与404错误的解决
- CoordinatorLayout显示隐藏ToolBar
- Mysql笔记
- java基础知识,一些概念的区别总结
- 内存管理-SLAB(SLAB的基本数据结构)
- C++中的new、operator new与placement new
- HDU-1004Let the Balloon Rise
- Buy or Build UVA
- 【JavaEE】第一个JSP程序--了解JSP执行过程
- 汇编语言中OUT和IN的用法