前面讲了Design包的的CoordinatorLayout和SnackBar的混用,现在继续理解Design包的AppBar;

AppBarLayout跟它的名字一样,把容器类的组件全部作为AppBar.

如:

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
app:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar
app:layout_scrollFlags="scroll|enterAlways"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:id="@+id/main_toolbar"/> <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="悬停条目"/> </android.support.design.widget.AppBarLayout>

  

这里就是把Toolbar和TextView放到了AppBarLayout中,让他们当做一个整体作为AppBar。

引用appBar的

app:layout_scrollFlags="scroll|enterAlways"
属性,则可实现下拉的时候不显示appbar,上拉的时候显示appbar。这个在用户交互上真的挺好用的。 再来看看可折叠的ToolBar
 <android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
app:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_height="wrap_content">
<!--可折叠的toolbar-->
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_collapseMode="parallax"
android:src="@mipmap/ic_launcher"/> <android.support.v7.widget.Toolbar
app:layout_scrollFlags="scroll|enterAlways"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:id="@+id/main_toolbar"/> </android.support.design.widget.CollapsingToolbarLayout> <!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="悬停条目"/>--> </android.support.design.widget.AppBarLayout>

  非常的简单。只需要在上面的代码中修改一下就可以了。

安卓Design包之AppBar和Toolbar的联用的更多相关文章

  1. 安卓Design包之Toolbar控件的使用

    转自:ToolBar的使用 ToolBar的出现是为了替换之前的ActionBar的各种不灵活使用方式,相反,ToolBar的使用变得非常灵活,因为它可以让我们自由往里面添加子控件.低版本要使用的话, ...

  2. 安卓Design包之TabLayout控件的使用

    转自: 安卓Design包之TabLayout控件的简单使用 Google在2015的IO大会上,给我们带来了更加详细的Material Design设计规范,同时,也给我们带来了全新的Android ...

  3. 安卓Design包下的TextInputLayout和FloatingActionButton的简单使用

    终于介绍到Design包的最后的东西了. 也很简单,一个是TextInputLayout. TextInputLayout作为一个父容器,包含一个新的EditText,可以给EditText添加意想不 ...

  4. 安卓Design包之超强控件CoordinatorLayout与SnackBar的简单使用

    在前面的Design中,学习使用了TabLayout,NavigationView与DrawerLayout实现的神奇效果,今天就带来本次Design包中我认为最有意义的控件CoordinatorLa ...

  5. 安卓Design包之TabLayout控件的简单使用

    Google在2015的IO大会上,给我们带来了更加详细的Material Design设计规范,同时,也给我们带来了全新的Android Design Support Library,在这个supp ...

  6. 安卓Design包之CoordinatorLayout配合AppBarLayout,ToolBar,TabLaout的使用

    转载: CoordinatorLayout配合AppBarLayout,Toolbar和TabLayout的使用 控件的简单介绍: AppBarLayout:它是继承LinerLayout实现的一个V ...

  7. 安卓Design包之NavigationView结合DrawerLayout,toolbar的使用,FloatingActionButton

    注意:使用前需要添加Design依赖包,使用toolbar时需要隐藏标题头 FloatingActionButton 悬浮按钮:FloatingActionButton是重写ImageView的,所有 ...

  8. 安卓Design包之CollapsingToolbarLayout(可折叠的工具栏布局)的简单使用

    转自: CollapsingToolbarLayout的使用 注意:使用前需要添加Design依赖包,使用toolbar时需要隐藏标题头 CollapsingToolbarLayout作用是提供了一个 ...

  9. 带你实现开发者头条APP(四)---首页优化(加入design包)

    title: 带你实现开发者头条APP(四)---首页优化(加入design包) tags: design,Toolbar,TabLayout,RecyclerView grammar_cjkRuby ...

随机推荐

  1. 用php做注册审核

    做注册审核就像前面讲的注册登录一样,也是要连接数据库 首先在数据库内要做这样一张表: 表名为users表 里面的列名分别为用户名,密码,姓名,性别,生日,账户的状态,照片 然后就可以写代码了,要注册的 ...

  2. [原创]mybatis中整合ehcache缓存框架的使用

    mybatis整合ehcache缓存框架的使用 mybaits的二级缓存是mapper范围级别,除了在SqlMapConfig.xml设置二级缓存的总开关,还要在具体的mapper.xml中开启二级缓 ...

  3. HTML5 sessionStorage会话存储

    sessionStorage 是HTML5新增的一个会话存储对象,用于临时保存同一窗口(或标签页)的数据,在关闭窗口或标签页之后将会删除这些数据.本篇主要介绍 sessionStorage(会话存储) ...

  4. spring boot 部署为jar

    前言 一直在ide中敲代码,使用命令行mvn spring-boot:run或者gradlew bootRun来运行spring boot项目.想来放到prod上面也应该很简单.然而今天试了下,各种问 ...

  5. EntityFramework 6 + Mysql 生成POCOs

    问题 使用EDMX文件 EF Power Tools参数不正确的解决方法 对于"异常来自 HRESULT:0x80070057 (E_INVALIDARG)",有方法说" ...

  6. TCP通信

    //网络套接字编程实例,服务器端,TCP通信. #include <WinSock2.h> #pragma comment(lib,"ws2_32.lib") #inc ...

  7. 应用Grunt自动化地优化你的项目前端

    在不久前我曾写了一篇 应用r.js来优化你的前端 的文章,为大家介绍了r.js这个实用工具,它可以很好地压缩.合并前端文件并打包整个项目.但是如果将r.js放到项目中,我们不得不顾及到一个问题——项目 ...

  8. a different object with the same identifier value was already associated with the session:

    hibernate操作: 实例化两个model类,更新时会提示  a different object with the same identifier value was already assoc ...

  9. JavaScript语法

    通用变量var 强制整数parseint(): 强制小数parsefloat(): 是不是一个合法的数字isNaN(): if(判断条件) { 满足条件要执行的语句 } else{ 不满足条件要执行的 ...

  10. Android Studio 轻松整理字符串到string.xml中

    昨天了解了Alt+Enter快捷键的大用处,今天又发现了一个快捷的方法,必须记下来.转载请注明出处http://www.cnblogs.com/LT5505/p/5466630.html 1.首先代码 ...