android - ScrollView 滚动时如何隐藏和显示 Material 工具栏?

标签 android material-design toolbar

在我的 android 应用程序中,我在 RelativeLayout 中构建了一个简单的 ScrollView!它还有一个 Material Toolbar。当用户向上滚动时,如何使 Material 工具栏随过渡隐藏,并在用户向下滚动时显示工具栏?这是我的应用程序的 xml 布局结构。

<RelativeLayout>
    <AppBarLayout>
        <Toolbar/>
    </AppBarLayout>

    <ScrollView> 
        <!-- views -->
    </ScrollView>
</RelativeLayout>

最佳答案

使用带有 CollapsingToolbarLayout 的 NestedScrollView

<android.support.v4.widget.NestedScrollView ...>
    <LinearLayout ...>
        ...
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

Try this working example

关于android - ScrollView 滚动时如何隐藏和显示 Material 工具栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32675688/

相关文章:

java - 如何使用 onItemClickListener 在单击时展开 listView?

android - 如何将数组中的值填充到 SQLite 数据库中

android - 获取建筑物的位置

android - 在 AppTheme 中设置了 colorBackground 的 AppCompat Spinner 样式背景?

android - 带有操作按钮的 snackbar 未与文本对齐

android - 单击 recyclerView 时打开文件(pdf,mp3,mp4,...)

ios - 工具栏和选择器之间的差距?

android - 如何使新 Activity 在 Android 中可见

c# - 在已经添加项目后,如何向 UIToolbar 添加/删除 UIBarButtonItem?

Android 自定义工具栏 onOptionsItemSelected 不工作