标签: android-appbarlayout

CoordinatorLayout在滚动结束时折叠或展开AppBar

有没有办法根据滚动结束时可见的可折叠视图的百分比向上或向下移动AppBar.在CheeseSquare应用程序中,当滚动结束时,工具栏会卡在两者之间.

谢谢

android android-coordinatorlayout android-appbarlayout

1
推荐指数
1
解决办法
2612
查看次数

如何使CollapsingToolbar具有"wrap_content"高度?

我想制作搜索工具栏,无论滚动级别如何,都会向下滑动并在向上滑动时折叠.当我想将此工具栏的高度设置为搜索区域时遇到问题.在向下滑动它很好.但在向上滑动搜索图标仍然可见. 在此输入图像描述 例如,如果我将AppBarLayout android:layout_height ="wrap_content"更改为100dp,则可以隐藏工具栏,但它看起来很糟糕,可能会导致不同分辨率出现问题.我想要实现的例子是在Play Market应用程序中搜索,它是如何在那里完成的?

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="test.proekt101_test.MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay"
    android:layout_height="wrap_content">
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        >
                    <SearchView
                    android:id="@+id/searchView1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginTop="30dp"
                    >
                </SearchView>
                </android.support.design.widget.CollapsingToolbarLayout>
            </android.support.design.widget.AppBarLayout>

            <include layout="@layout/content_main" />

        </android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout

1
推荐指数
1
解决办法
2673
查看次数

AppBarLayout与RecyclerView重叠

我一直在寻找解决这个问题的一段时间没有成功.我的AppBarLayout与我的一个xml文件中的RecyclerView重叠.我尝试重新排列视图而没有任何积极的结果.任何帮助表示赞赏.这是我的代码:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:background="@color/bg_register">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/toolbar"/>

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

        <include layout="@layout/content"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:id="@+id/x"/>
    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/activity_main_drawer"
        android:clickable="true"/>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

这是内容的xml文件:

<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"
                xmlns:tools="http://schemas.android.com/tools"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:orientation="vertical"
                android:background="@color/bg_register"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                tools:showIn="@layout/activity">

    <TextView
        android:padding="5dp"
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/list" />

    <android.support.v7.widget.RecyclerView
        android:layout_below="@id/textView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/lv_recycler"
        android:background="@color/white"
        android:scrollbars="vertical"
        android:clickable="true"
        android:fadeScrollbars="true"/>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-recyclerview android-appbarlayout

1
推荐指数
1
解决办法
3302
查看次数

在 AppBarLayout 的 Toolbar 下制作 SwipeRefreshLayout

SwipeRefreshLayout用作布局的根元素,因为我需要刷新屏幕上的所有内容。布局如下:

<SwipeRefreshLayout>
    <CoordinatorLayout>
        <ViewPager />
        <AppBarLayout>
            <Toolbar />
            <FrameLayout>
                ...
            </FrameLayout>
        <TabLayout />
    </CoordinatorLayout>
</SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)

当我在布局上向下滑动时,刷新圈SwipeRefreshLayout出现在屏幕顶部,位于Toolbar. 所以我使用SwipeRefreshLayout#setProgressViewOffset让圆圈从工具栏高度的偏移量开始,但是当刷新完成时,圆圈会在消失之前奇怪地挂在工具栏上一会儿:截图

如何在工具栏下制作刷新圆圈?

android swiperefreshlayout android-toolbar android-appbarlayout

1
推荐指数
1
解决办法
3234
查看次数

无法在AppBarLayout/CollapsingToolbar上获得阴影

我在AppBarLayout上获得阴影时遇到问题.以下是我的活动的xml布局,谁能看到问题出在哪里?我在这里检查了几个非常相似的问题,一切都应该正确设置...

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ui.main.MainActivity"

    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/main_app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:elevation="15dp"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/main_collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
            app:collapsedTitleTextAppearance="@style/Base.Widget.AppCompat.Toolbar"
            app:expandedTitleTextAppearance="@style/Base.Widget.AppCompat.Toolbar"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            >

            <android.support.percent.PercentRelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_collapseMode="parallax"
                >

                ... Content ...

            </android.support.percent.PercentRelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/main_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            </android.support.v7.widget.Toolbar>

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

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/main_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginEnd="1dp"
        android:layout_marginRight="1dp"
        android:paddingBottom="@dimen/main_recycler_bottom_padding"
        android:clipToPadding="false"
        android:overScrollMode="never"
        android:layout_below="@+id/app_bar_layout"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/attribute_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginBottom="@dimen/default_padding"
        app:borderWidth="0dp"
        android:backgroundTint="@color/colorPrimary"
        android:src="@drawable/ic_add_white"/>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

此外,Android系统报警应用程序中还有一个小功能,只有当活动内容向下滚动时,它们才会在工具栏中添加阴影,任何人都有指向如何实现此类事情的指示?

android elevation android-collapsingtoolbarlayout android-appbarlayout

1
推荐指数
1
解决办法
1144
查看次数

在TabLayout下的AppBarLayout中添加自定义阴影?

我已经添加了我的下面自定义阴影TabLayoutAppBarLayout,但由于某些原因,还有的阴影之下的绿色背景:

在此输入图像描述

如果不够清楚,这里又是一个更长的阴影:

在此输入图像描述

正如你所看到的,阴影下方有一个绿色背景,我不知道如何摆脱它.

然后我注意到,在"设计"选项卡中,AppBarLayout背景设置为绿色(即使它未在布局的XML中设置为任何颜色):

在此输入图像描述

我尝试将颜色更改为@android:color/transparent,但它使背景(在上面的图片中的阴影后面)变白,并且不透明.所以我仍然不确定发生了什么.

这是我的布局:

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

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:elevation="0dp">

        <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/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tablayout"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            app:layout_scrollFlags="scroll|enterAlways"
            app:tabBackground="@color/colorPrimary"
            app:tabIndicatorColor="@android:color/white"
            app:tabSelectedTextColor="@android:color/white"
            app:tabTextAppearance="@style/TabTextAppearance"
            app:tabTextColor="@color/colorTabText" />

        <View
            android:layout_width="match_parent"
            android:layout_height="8dp"
            android:background="@drawable/toolbar_shadow" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

这是toolbar_shadow.xml可绘制的:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android">

    <gradient
        android:startColor="@android:color/transparent"
        android:endColor="@color/shadowColor"
        android:angle="90" />

</shape>
Run Code Online (Sandbox Code Playgroud)

这是颜色(20%不透明度):

<color name="shadowColor">#33423f3f</color>
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

android android-layout android-styles android-toolbar android-appbarlayout

1
推荐指数
1
解决办法
1470
查看次数

工具栏标题未显示

两种情况下都没有显示工具栏标题是否已折叠.下面是我的布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:background="@android:color/transparent"
            android:fitsSystemWindows="true">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="@dimen/collapsing_toolbar_height"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleTextAppearance="@android:color/transparent"
                android:fitsSystemWindows="true">

                <ImageView
                    android:id="@+id/header_image"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/collapsing_toolbar_height"
                    android:scaleType="centerCrop"
                    android:fitsSystemWindows="true"
                    android:contentDescription="@string/app_name"
                    android:src="@mipmap/ic_launcher"
                    app:layout_collapseMode="parallax"/>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    android:title="@string/app_name"
                    app:layout_collapseMode="pin" />

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

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



    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:layout_marginBottom="100dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <RelativeLayout
            android:id="@+id/rlMain"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <FrameLayout
                android:id="@+id/container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"></FrameLayout>


        </RelativeLayout>



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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.design.widget.BottomNavigationView
            android:id="@+id/bottom_navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            app:itemBackground="@color/faint_black"
            app:itemIconTint="@color/white"
            app:itemTextColor="@color/menu_item_color_change"
            app:menu="@menu/menu" />
    </RelativeLayout>




</android.support.design.widget.CoordinatorLayout >
Run Code Online (Sandbox Code Playgroud)

android android-toolbar android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout

1
推荐指数
1
解决办法
1093
查看次数

移除 AppBarLayout 周围的边框

我有一个看起来像这样的片段:

截屏

在屏幕底部(底部导航栏的正上方)彼此相邻的粉红色圆点和灰色圆点的正上方,有一条水平灰线。

无论如何我可以删除它吗?

该片段具有以下布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".home.tutorial.TutorialFragment">



<android.support.v4.view.ViewPager
    android:id="@+id/tutorialViewPager"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toTopOf="@+id/appBar"
    android:background="@android:color/white"/>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    app:layout_constraintTop_toBottomOf="@id/tutorialViewPager"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent">

    <me.relex.circleindicator.CircleIndicator
        android:id="@+id/circleIndicator"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        app:ci_drawable="@drawable/tab_indicator_selected"
        app:ci_drawable_unselected="@drawable/tab_indicator_default"
        app:ci_height="6dp"
        app:ci_width="6dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"/>


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

</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

我看了这篇文章:删除操作栏边框

但考虑到我不想从操作栏中删除边框,我认为它不适用。

android android-xml android-appbarlayout

1
推荐指数
1
解决办法
2222
查看次数

NestedWebView 与 ScrollingViewBehavior 一起正常工作

我有两个活动,一个应用程序扩展相同的abstract-一个与WebView另一个具有ViewPagerTabLayoutRecyclerView的S -和在这个层面上,我实现“共享”显示/隐藏工具栏与滚动/一扔功能:

app:layout_scrollFlags="scroll|snap|enterAlways"

WebViewToolbar就像RecyclerViewViewPager(保持TabLayout可见)中的任何选项卡下一样“推出” ,在这两种情况下,任何滚动到顶部都会带回Toolbar. 就像在这个例子中一样:

用滚动隐藏

现在我必须改变这种行为 -Toolbar当用户不在页面顶部时应该隐藏,所以:Toolbar如果存在任何滚动到底部应该隐藏并且只有(滚动到顶部 && getScrollY()<=0)应该Toolbar输入:

只隐藏在顶部

我从指南中借用了 GIF ,这表明(所有其他的)我想要的行为是默认的,只有scroll标志(可能还有snap)。所以我已经删除了enterAlways,我的“本机”Activity开始按预期开箱即用。WebView- 根本没有变化......

我怀疑这个错误是我造成的NestedWebView,我目前使用的一个。所以我试图用这些来替换这个类:

marshi - 不可滚动的 webview 内容(工具栏显示/隐藏)

takahirom - 即使在 1px 几乎立即向上滚动时,工具栏也会进入(一种捕捉行为,但在触摸期间)

hanks - 没有嵌套滚动(固定工具栏),还有未注释的setNestedScrollingEnabled(true);

如何实现Toolbar与GIF合作的第二个 GIF行为WebView

android android-webview android-scroll android-toolbar android-appbarlayout

1
推荐指数
1
解决办法
1071
查看次数

如何从 AppBar 布局或工具栏底部删除阴影或分隔线?

在此输入图像描述

我想从 AppBar 布局或工具栏底部删除阴影或分隔线

这是我的 xml 代码

海拔,actionBarDivider 已经尝试过。

<com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="0dp"
            android:theme="@style/AppTheme.AppBarOverlay">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/colorPrimaryDark"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

 </com.google.android.material.appbar.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-toolbar android-appbarlayout

1
推荐指数
1
解决办法
1861
查看次数