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. Mysql查看执行计划-explain

    最近生产环境有一些查询较慢,需要优化,于是先进行业务确认查询条件是否可以优化,不行再进行sql优化,于是学习了下Mysql查看执行计划. 语法 explain <sql语句>  例如: e ...

  2. UIDynamic(捕捉行为)

    一.简介 可以让物体迅速冲到某个位置(捕捉位置),捕捉到位置之后会带有一定的震动 UISnapBehavior的初始化 - (instancetype)initWithItem:(id <UID ...

  3. redis源码安装

    #安装目录 mkdir -p /data/apps/redis cd /data/tgz wget http://download.redis.io/releases/redis-3.2.1.tar. ...

  4. php多文件压缩下载

    /*php多文件压缩并且下载*/ function addFileToZip($path,$zip){ $handler=opendir($path); //打开当前文件夹由$path指定. whil ...

  5. Root--超级用户

    http://www.shuame.com/root/  root (计算机术语言) ROOT存在于Linux系统.UNIX系统(如AIX.BSD等)和类UNIX系统(如稳定到服务器都在用的Debia ...

  6. Django基础,Day9 - 静态文件目录与路径设置说明(eg. images, JavaScript, CSS)

    静态文件路径设置官方说明 1. Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS. 2. In ...

  7. 数据存储_SQLite常用的函数

    一.简单说明 1.打开数据库 int sqlite3_open( const char *filename,   // 数据库的文件路径 sqlite3 **ppDb            // 数据 ...

  8. 【转载】使用pandas进行数据清洗

    使用pandas进行数据清洗 本文转载自:蓝鲸的网站分析笔记 原文链接:使用python进行数据清洗 目录: 数据表中的重复值 duplicated() drop_duplicated() 数据表中的 ...

  9. Android studio 相关错误处理

    1.android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"  -->  在Activity中设置,表 ...

  10. 布局之按钮的图片分辨率--Android Studio

    在布局页面,想把取消按钮和确认钮大小一致,刚开始想法是错的,不用在控制层设置,也不用在布局层压缩图片,有两个方法法: 1.直接用美图秀秀“尺寸”功能,修改成另一按钮一样的分辨率. 2.设置按钮相同高度 ...