android - 触发 AppBar 返回其在 CoordinatorLayout 内的正常位置

标签 android android-layout android-coordinatorlayout coordinator-layout

我有下一个布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
            android:id="@+id/layout_offer_detail_coordinator"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar_offer_details"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_scrollFlags="scroll|enterAlways|snap" />

        </android.support.design.widget.AppBarLayout>

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/layout_offer_detail_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorBackground"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

        </>
    </>
</>

当用户在列表中向下滚动时,这将隐藏应用栏,并在用户向上滚动时显示它。

我的问题是,在NestedScrollView的末尾,我有一个“返回顶部”按钮,单击该按钮将触发scrollView向上滚动:scrollView.smoothScrollTo( 0, 0);

问题在于,当用户滚动到顶部时,appBar 不会返回。我无法以编程方式触发应用栏返回。

有什么想法吗?!

编辑

该功能取自此处:see link

最佳答案

这比我想象的要容易。经过三个小时的搜索和尝试,我只需要这样做:

appBarLayout.setExpanded(true, true);

好吧,这对我来说是不必要的时间浪费......

关于android - 触发 AppBar 返回其在 CoordinatorLayout 内的正常位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58587529/

相关文章:

android - MapFragment导致ViewPager闪烁

java - 安卓交互器测试

Android 图像/视频错误地逆时针旋转 90 度

android - 工具栏不滚动

android - 隐藏工具栏时无法启用 webview 的滚动行为

java - 找不到符号方法 addOnPageChangeListener

java - 特定用户的所有通知都将从数据库中删除,而实际上只应删除一条通知

android - 使用 PlaybackOverlayFragment 隐藏当前时间

android - 错误 :error: 'drawable/delete.png' is incompatible with attribute android:background (attr) reference|color

Android 4.2.2 map fragment 问题