昨天一直在琢磨为什么Toolbar和CollapsingToolbarLayout一起使用时menu item无点击放应的原因,后来在stackoverflow上一条回答,说可能是Toolbar的背景颜色太深导致点击时的水波纹不明显。这个启发了我,会不会是跟toolbar的背景有关呢?贴上代码:

  

  1. <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:app="http://schemas.android.com/apk/res-auto"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:fitsSystemWindows="false"
  6. android:orientation="vertical">
  7.  
  8. <android.support.design.widget.AppBarLayout
  9. android:id="@+id/appbar"
  10. android:layout_width="match_parent"
  11. android:layout_height="200dp"
  12. android:fitsSystemWindows="false"
  13. android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
  14. app:elevation="0dp">
  15.  
  16. <android.support.design.widget.CollapsingToolbarLayout
  17. android:id="@+id/collapsing_toolbar"
  18. android:layout_width="match_parent"
  19. android:layout_height="match_parent"
  20. app:contentScrim="?attr/colorPrimary"
  21. app:expandedTitleMarginEnd="64dp"
  22. app:expandedTitleMarginStart="48dp"
  23. app:layout_scrollFlags="scroll|exitUntilCollapsed">
  24.  
  25. <ImageView
             android:layout_width="match_parent"
                    android:layout_height="48dp"/>
  26.  
  27. <android.support.v7.widget.Toolbar
  28. android:id="@+id/home_page_toolbar"
  29. android:layout_width="match_parent"
  30. android:layout_height="48dp" android:minHeight="44dp"
  31. app:layout_collapseMode="pin"
  32. app:navigationIcon="@mipmap/nav_menu"
  33. app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
  34.  
  35. <TextView
  36. android:id="@+id/home_page_toolbar_title"
  37. android:layout_width="wrap_content"
  38. android:layout_height="wrap_content"
  39. android:layout_alignParentLeft="true"
  40. android:layout_centerInParent="true"
  41. android:text="首页"
  42. android:textColor="@color/white"
  43. android:textSize="@dimen/textsize_zhuche" />
  44.  
  45. </android.support.v7.widget.Toolbar>
  46.  
  47. </android.support.design.widget.CollapsingToolbarLayout>
  48.  
  49. </android.support.design.widget.AppBarLayout>
  50.  
  51. <LinearLayout
  52. android:layout_width="match_parent"
  53. android:layout_height="match_parent"
  54. android:orientation="vertical"
  55. app:layout_behavior="@string/appbar_scrolling_view_behavior">
  56.  
  57. <android.support.design.widget.TabLayout
  58. android:id="@+id/tab_FindFragment_title"
  59. android:layout_width="match_parent"
  60. android:layout_height="35dp"
  61. android:background="@color/homepage_toolbar_color"
  62. android:elevation="@dimen/tablayout_elevation"
  63. app:tabIndicatorColor="@color/white"
  64. app:tabIndicatorHeight="@dimen/tabindicatorheight"
  65. app:tabMode="fixed"
  66. app:tabSelectedTextColor="@color/white"
  67. app:tabTextAppearance="@style/tabLayoutTextSize"
  68. app:tabTextColor="#F8BBD0" />
  69.  
  70. <android.support.v4.widget.SwipeRefreshLayout
  71. android:id="@+id/refresh"
  72. android:layout_width="match_parent"
  73. android:layout_height="match_parent">
  74.  
  75. <android.support.v4.view.ViewPager
  76. android:id="@+id/homepage_viewpager"
  77. android:layout_width="match_parent"
  78. android:layout_height="match_parent" />
  79.  
  80. </android.support.v4.widget.SwipeRefreshLayout>
  81.  
  82. </LinearLayout>
  83.  
  84. </android.support.design.widget.CoordinatorLayout>

发现果然toolbar没有设置背景,于是设置

  1. android:background="@color/red"
    果然toolbar上的memu item有点击反馈了有木有!
  2.  
  3. 可是这样Toolbar就会永远占据一行的位置,我想要的是CollapsingToolbarLayout扩展的时候toolbar变得透明,像这样
  1. 解决办法是toolbar的背景设置成透明色,
  1. android:background="@color/transprant"
    这样就既能有点击反馈,又能实现上面的效果。
    运行效果:
  1.  
  1.  

Toolbar 和 CollapsingToolbarLayout一起使用时menu item无点击反应解决办法的更多相关文章

  1. ListView中的Item不能点击的解决方法

    有时,为了实现某种功能,在Android程序中会考虑在ListView的每一个Item中添加一个Button(或ImageButton等). 但是,这样会出现一个问题: 当同时设置了Button的on ...

  2. SpringBoot框架:两个方法同时调用时父方法使内部方法的DataSource注解失效的解决办法

    一.问题如下: 使用的是SpringBoot框架:通过AOP和自定义注解完成druid连接池的动态数据源切换(三)中的两个数据库spring_boot_demo和other_data. 在UserCo ...

  3. Android自定义ListView的Item无法响应OnItemClick的解决办法

     转: 如果你的自定义ListViewItem中有Button或者Checkable的子类控件的话,那么默认focus是交给了子控件,而ListView的Item能被选中的基础是它能获取Focus,也 ...

  4. Android自定义ListView的Item无法响应OnItemClick的解决办法(转)

    原文链接:http://www.linuxidc.com/Linux/2011-09/43205.htm 如果你的自定义ListViewItem中有Button或者Checkable的子类控件的话,那 ...

  5. ubuntu16.04登录后无dash,无启动栏launch,无menu bar,只有桌面背景解决办法

    今天打开电脑,与往常一样输入用户名密码登录后,发现桌面上空空如也,启动栏launch,menu bar什么的都消失了,桌面上文件可以打开,但是无法拖动位置,无法关闭(因为menu bar没了,无法鼠标 ...

  6. 网易MuMu模拟器不显示Menu(菜单)键的解决办法

    解决方法一: 前提:需要一个键盘 步骤: 1.直接按下键盘上的Menu键. 解决方法二: 前提:需要Root之后的文件浏览器 步骤: 1.在文件管理器中打开 /System 文件夹: 2.复制 bui ...

  7. 关于vs2013error C4996: 'strcmpi': The POSIX name for this item is deprecated.的错误解决办法!

    1.出现如下错误(如图1) 2.解决办法(如图2)在头文件处添加#pragma warning(disable: 4996)

  8. Alamofire使用报错Extra argument 'method' in call解决办法

    使用Alamofire的时候,在用这句的时候报错了: Extra argument 'method' in call Alamofire.request("", method: H ...

  9. eclilpse svn : Item is out of date 解决办法

    尝试以下方面, 1. 2.如果上面的还不行,就说明你修改了原有项目结构,可能是增加了新包,或者重命名的包或文件,那么你得先update,然后再提交 这样就OK了,我就是用了2才成功的哦.

随机推荐

  1. 未在本地计算机上注册"Microsoft.ACE.OLEDB.12.0"提供程序

    运行时出现了错误,提示未在本地计算机上注册"Microsoft.ACE.OLEDB.12.0"提供程序. 这个问题的原因是64位PC上安装了Office的32位版本,所以Micro ...

  2. nginx配置时的一些问题

    在配置nginx的时候出现的一些问题,在此记录: 1.如何打开nginx服务: 方法1:打开解压的下载文件,双击打开nginx.exe即可(出现闪退,我以为是出问题了,其实是服务已经启动了) 方法2: ...

  3. CODEVS 3138 栈练习2

    3138 栈练习2  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description (此题与栈练习1相比改了2处:1加强了数据 2不保证栈空时 ...

  4. 【干货】.NET开发通用组件发布(二) 邮件发送组件

    组件介绍和合作开发 http://www.cnblogs.com/MrHuo/p/MrHuoControls.html 邮件发送组件 邮件发送组件采用常用的SMTP发送方式,需要添加以下格式的配置文件 ...

  5. Funny String

    def main(): t = int(raw_input()) for _ in xrange(t): s = raw_input().strip() s_len = len(s) is_funny ...

  6. 64位Ubuntu14.04搭建ADT开发环境

    本来放假是要出去玩的,结果出游计划拖到了周一,今天先来无事看看ubuntu最近发展得怎么样了,顺便把ADT也搭建好,方便以后研究android框架.想想在windows下,ADT直接down下来解压就 ...

  7. C#编程实现朴素贝叶斯算法下的情感分析

    C#编程实现 这篇文章做了什么 朴素贝叶斯算法是机器学习中非常重要的分类算法,用途十分广泛,如垃圾邮件处理等.而情感分析(Sentiment Analysis)是自然语言处理(Natural Lang ...

  8. jqGrid添加详细按钮,单击弹出窗体

    代码如下: @using WebMap.Framework.UI; @using WebMap.Admin.Models; @using WebMap.Core; @using WebMap.Core ...

  9. 使用Hexo搭建GitPage

    资料: hexo官方文档:https://hexo.io/zh-cn/docs/ jekyll官方文档:http://jekyll.com.cn/docs/home/ 简介: 使用hexo和jekyl ...

  10. GridView 设置背景透明以及Item的点击动画

    //将点击时的背景色设置为透明 gridView.setSelector(new ColorDrawable(Color.TRANSPARENT)); 此时点击GridView的每个Item就不会出现 ...