当你的才华还撑不起你的梦想时,你只能一直前进!

安卓Design包之AppBar和Toolbar的联用

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

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

如:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<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的

1
app:layout_scrollFlags="scroll|enterAlways"<br>属性,则可实现下拉的时候不显示appbar,上拉的时候显示appbar。这个在用户交互上真的挺好用的。<br><br><br><br>再来看看可折叠的ToolBar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<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>

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

 

posted @   南尘  阅读(1196)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述

写不完的矫情,做不完的开源

点击进入我的GitHub页
南 尘
主 页
优美钢琴曲合集-南尘.mp3                    感谢您阅读我的博客,如果您现在工作、学习累了或者疲惫了,不妨聆听一下音乐,它能够减轻你的疲劳,还能够带给您一种舒适愉悦的心情。(样式取自博客园-欲泪成雪)
点击右上角即可分享
微信分享提示