android - 高度和阴影错误的工具栏

标签 android material-design android-design-library

我正在尝试使用高度和设计库向工具栏添加阴影。布局代码类似于:

<android.support.design.widget.CoordinatorLayout ... >
  <android.support.design.widget.AppBarLayout ... >
    <android.support.design.widget.CollapsingToolbarLayout ... >
       <android.support.v7.widget.Toolbar
           android:id="@+id/app_bar"
           android:layout_width="match_parent"
           android:layout_height="?actionBarSize"
           app:contentInsetStart="16dp"
           android:background="@color/colorPrimary"
           android:elevation="16dp"
        />
    </android.support.design.widget.CollapsingToolbarLayout>
  </android.support.design.widget.AppBarLayout>

完整的应用程序源代码可在 github 上获得.

问题是工具栏高度或阴影的行为与我预期的不同。如果您观看下面的屏幕截图,您会发现问题所在。

我需要做的是显示蓝色区域下方的阴影。

Current Toolbar

非常感谢任何提示。

最佳答案

如前所述there ,这是通过 CollapsingToolbarLayout 的实现实现的 - 如果 CollapsingToolbarLayout 显示非固定元素,则移除提升:

if (Math.abs(verticalOffset) == scrollRange) {
  // If we have some pinned children, and we're offset to only show those views,
  // we want to be elevate
  ViewCompat.setElevation(layout, layout.getTargetElevation());
} else {
  // Otherwise, we're inline with the content
  ViewCompat.setElevation(layout, 0f);
}

因此,我只能建议通过从 Google 复制原始 CollapsingToolbarLayout 来制作您自己的 CollapsingToolbarLayout,并在此条件下进行更改。

关于android - 高度和阴影错误的工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34970507/

相关文章:

安卓模拟器经常崩溃

android - 无法在 Playstore 中按应用名称找到应用

android - 文本在 Android 中被截断以响应 native

Android SupportActionBar 不刷新标题

android - float 按钮在 Lollipop 前版本中不起作用

java - 将 Drawable 放置在按钮的右侧

android - Material Design - 将卡片扩展(过渡)到全屏

android - 如何实现 Material Design Choreographing 表面动画

android - 小写的 TabLayout 选项卡标题文本

android - 带工具栏和 fragment 的 CoordinatorLayout