Theme

ActionBar / ToolBar

android.support.design.widget.CollapsingToolbarLayout

android.support.design.widget.AppBarLayout

@、Theme

1、设置NoActionBar

<resources>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#3F51B5</item>
<!-- Light Indigo -->
<item name="colorPrimaryDark">#3949AB</item>
<!-- Dark Indigo -->
<item name="colorAccent">#00B0FF</item>
<!-- Blue -->
</style>
<style name="AppTheme" parent="AppTheme.Base"></style>
</resources>

@、ActionBar / ToolBar

1、Theme设置为NoActionBar,Layout文件中添加

        <android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

然后再代码中设置此Toolbar为ActionBar

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); // 设置ActionBar
ActionBar supportedActionBar = getSupportActionBar();
if(supportedActionBar != null){
// 设置向上导航的图标。默认为向左的箭头
supportedActionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
// 设置是否显示向上导航: true显示,false不显示;默认为false.
supportedActionBar.setDisplayHomeAsUpEnabled(true);
}

相关知识:

a、如果没有在onOptionsItemSelected中对android.R.id.home进行处理,则:在AndroidManifest中相应的activity指定了android:parentActivityName,就返回到parentActivity,否则什么都不做。

b、如果是返回parentActivity,则parentActivity会onDestroy, onCreate, onStart, onResume执行一遍。而如果是按返回键,则只是(onStart), onResume。对于主界面有Tab页的时候要注意考虑这种情况。

c、在onOptionsItemSelected进行判断,如果是android.R.id.home,则直接调用finish(),这样也可以到达按返回键的效果。当然如果onBackPressed()没有做特殊处理的话,也可以调用onBackPressed()。

d、应用场景:使用此方法为侧边导航栏添加指示器。

@、android.support.design.widget.CollapsingToolbarLayout

1、对Tookbar进行包装。

2、如果collaspsingToolbarLayout的app:layout_scrollFlags设置为exitUntilCollasped,则对子控件设置app:layout_collapseMode:pin(固定不动,Toolbar上的向上导航和菜单按钮不会消失), parallax(随着CollapsingToolbarLayout移动而移动,Toolbar上的向上导航和菜单按钮会消失),不过最后的高度和宽度就是Toobar的高度和宽度。

3、app:contentScrim指定了最终显示的内容。

@、android.support.design.widget.AppBarLayout

原来这些实现是需要CoordinatorLayout的配合,在使用中竟然没有注意到这点,看了这篇文章,总算有所明白了Handling Scrolls with CoordinatorLayout

1、对子控件设置app:layout_scrollFlags:sroll(向上滑(滚动条向下滑),子控件一起向上滑), enterAlways(向下滑(滚动条向上滑),不管滚动条是否滑到顶,子控件都出现,如果不指定该值,则要等滚动条滑到顶,子控件才会出现), enterAlwaysCollasped(这个没有测试出有什么用??), exitUntilCollasped(结合CollapsingToolbarLayout使用,如果CollapsingToolbarLayout的Toolbar把app:layout_collapseMode设置为pin,则该Toolbar上的向上导航和菜单按钮不会消失)。

示例一:AppBarLayout + Toolbar + TabLayout,滑动时Toolbar隐藏,Tab标签保留

       <android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- 配合Theme设置为Theme.AppCompat.Light.NoActionBar使用,这样ActionBar的文字就是浅色的了 -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> <android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>

示例二: AppBarLayout + CollapsingToolbarLayout + Toolbar

    <android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="256dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="72dp"
app:expandedTitleMarginStart="16dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"> <ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
tools:background="@drawable/a"/> <android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="parallax"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

Android -- 案例学习积累的更多相关文章

  1. Android WiFiDirect 学习(二)——Service Discovery

    Service Discovery 简介 在Android WifiDirect学习(一 )中,简单介绍了如何使用WifiDirect进行搜索——连接——传输. 这样会有一个问题,那就是你会搜索到到附 ...

  2. Android开发学习之路-RecyclerView滑动删除和拖动排序

    Android开发学习之路-RecyclerView使用初探 Android开发学习之路-RecyclerView的Item自定义动画及DefaultItemAnimator源码分析 Android开 ...

  3. Android开发学习路线图

    Android开发学习方法: Android是一个比较庞大的体系,从底层的Linux内核到上层的应用层,各部分的内容跨度也比较大.因此,一个好的学习方法对我们学习Android开发很重要. 在此建议, ...

  4. Android动画学习(二)——Tween Animation

    前两天写过一篇Android动画学习的概述,大致的划分了下Android Animation的主要分类,没有看过的同学请移步:Android动画学习(一)——Android动画系统框架简介.今天接着来 ...

  5. Storm入门2-单词计数案例学习

     [本篇文章主要是通过一个单词计数的案例学习,来加深对storm的基本概念的理解以及基本的开发流程和如何提交并运行一个拓扑] 单词计数拓扑WordCountTopology实现的基本功能就是不停地读入 ...

  6. Android自动化学习笔记:编写MonkeyRunner脚本的几种方式

    ---------------------------------------------------------------------------------------------------- ...

  7. Android自动化学习笔记之MonkeyRunner:官方介绍和简单实例

    ---------------------------------------------------------------------------------------------------- ...

  8. android开发学习笔记000

    使用书籍:<疯狂android讲义>——李刚著,2011年7月出版 虽然现在已2014,可我挑来跳去,还是以这本书开始我的android之旅吧. “疯狂源自梦想,技术成就辉煌.” 让我这个 ...

  9. Android Animation学习(六) View Animation介绍

    Android Animation学习(六) View Animation介绍 View Animation View animation系统可以用来执行View上的Tween animation和F ...

随机推荐

  1. css-display:none和visibility:hidden的不同

    摘自张鑫旭老师的博客-- display:none和visibility:hidden都能使元素隐藏,但是有明显区别,主要有以下三点: 空间占据 重排与重绘 株连性 1.空间占据. 使用display ...

  2. BUG处理方案设计

    简介 当应用程序发布上线后,用户在使用的过程中可能会出现异常情况.对于这样的状况,如果能及时获取用户的异常信息,便能及早的分析和解决问题. 需要收集的信息 1. bug日志: 2.应用程序的版本号 3 ...

  3. 你所不了解的float(滥用float的怪异现象)

    float设计初衷就是为了实现文字环绕效果 原本页面流布局显示如上图所示,运用了float属性后就显示为如下图所示,这就是浮动的设计初衷 float的一些特性:包裹性.破坏性. 包裹的特性其实主要有三 ...

  4. <<< web里面Servlet高级应用的基础介绍

    Servlet中的页面跳转?两种方式,实现跳转:内部跳转(请求转发).外部跳转(重定向)内部跳转(请求转发)特点:在服务器内部完成页面之间的跳转:请求只有一次:浏览器地址不会改变.request.ge ...

  5. asp.net mvc 通过T4模板生成框架

    http://www.cnblogs.com/rdst/archive/2012/08/13/2637210.html http://www.kuqin.com/shuoit/20140716/341 ...

  6. 挣值管理(PV、EV、AC、SV、CV、SPI、CPI) 记忆

    挣值管理法中的PV.EV.AC.SV.CV.SPI.CPI这些英文简写相信把大家都搞得晕头转向的.在挣值管理法中,需要记忆理解的有三个参数:PV.AC.EV.     PV:计划值,在即定时间点前计划 ...

  7. 戴尔OMSA 使用指南

    戴尔的OMSA我们已经安装完成,但是没有web页面.因此我们目前想要看到服务器的相关硬件信息就需要使用命令行的方式获取了.那么,这里就介绍如何使用命令获取服务器硬件信息. 下面是我监控一些硬件信息的命 ...

  8. 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【开篇】【持续更新中。。。】

    最近发现web api很火,园内也有各种大神已经在研究,本人在asp.net官网上看到一个系列教程,原文地址:http://bitoftech.net/2013/11/25/detailed-tuto ...

  9. redis教程(整理中)

    一.redis简介 1.Redis:键值对类型的内存数据库:应用于高并发和实时请求的场景: 2.Redis常用数据类型: (1) string(基本数据类型)     (2)hash 注:hash中的 ...

  10. [NHibernate]NHibernate.Tool.hbm2net

    系列文章 [Nhibernate]体系结构 [NHibernate]ISessionFactory配置 [NHibernate]持久化类(Persistent Classes) [NHibernate ...