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. Could not execute action

    2.Could not execute action 原因:action成员变量有空值,要访问方法中,使用了该成员变量 参考: http://www.blogjava.net/javagrass/ar ...

  2. C#中中文编码的问题(StreamWriter和StreamReader默认编码)

    在使用StreamWriter和StreamReader时产生了这样的疑问,在不指定的情况下,他们使用什么编码方式? 查看MSDN,请看下图: 注意红色区域  这让我以为构造函数参数不同时使用不一样的 ...

  3. Vue.JS 对比其他框架

    Angular 选择 Vue 而不选择 Angular,有下面几个原因,当然不是对每个人都适合: 在 API 与设计两方面上 Vue.js 都比 Angular 简单得多,因此你可以快速地掌握它的全部 ...

  4. 手机端多种分享plugin插件地址

    //qq cordova plugin add https://github.com/iVanPan/Cordova_QQ.git --variable QQ_APP_ID=app_id 参考文档 h ...

  5. 【转】PHOTOSHOP常用快捷键大全

    PHOTOSHOP常用快捷键大全 一.文件新建 CTRL+N打开 CTRL+O 打开为 ALT+CTRL+O关闭 CTRL+W保存 CTRL+S 另存为 CTRL+SHIFT+S另存为网页格式 CTR ...

  6. SourceTree推送时,增加额外的远程仓库,不用每次都自定义粘贴复制网络

    一.命令行添加 二.软件界面可以查看到结果 更新,以上是代码添加了远程仓库,最近,找到了不用代码,直接在文件夹里写地址来添加的方式.直接上图了.

  7. LINQ驱动数据的查询功能

    一.LINQ概念 LINQ是微软在.NetFramework3.5中新加入的语言功能,在语言中以程序代码方式处理集合的能力. 1.1 LINQ VS 循环处理 在我刚工作时候,对于集合对象的处理一般是 ...

  8. [Nhibernate]体系结构

    引言 在项目中也有用到过nhibernate但对nhibernate的认识,也存留在会用的阶段,从没深入的学习过,决定对nhibernate做一个系统的学习. ORM 对象-关系映射(OBJECT/R ...

  9. ThinkPHP中疑难笔记

    不但要记住核心的东西, 还要记住 相关的 东西: 如php cli的版本是 5.6.14 bulit: sep 30, 2015 tp中, 通常说的系统就是框架; 项目就是 "应用程序&qu ...

  10. yaf学习资料

    yaf学习资料 文档 鸟哥的官方文档 Yaf框架结合PHPUnit的集成测试 php yaf框架扩展实践六--单元测试.计划任务.第三方库等 php yaf框架扩展实践一--配置篇 yaf实战例子 y ...