我想制作搜索工具栏,无论滚动级别如何,都会向下滑动并在向上滑动时折叠.当我想将此工具栏的高度设置为搜索区域时遇到问题.在向下滑动它很好.但在向上滑动搜索图标仍然可见.
例如,如果我将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
我一直在寻找解决这个问题的一段时间没有成功.我的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
我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
我在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
我已经添加了我的下面自定义阴影TabLayout中AppBarLayout,但由于某些原因,还有的阴影之下的绿色背景:
如果不够清楚,这里又是一个更长的阴影:
正如你所看到的,阴影下方有一个绿色背景,我不知道如何摆脱它.
然后我注意到,在"设计"选项卡中,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
两种情况下都没有显示工具栏标题是否已折叠.下面是我的布局
<?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
我有一个看起来像这样的片段:
在屏幕底部(底部导航栏的正上方)彼此相邻的粉红色圆点和灰色圆点的正上方,有一条水平灰线。
无论如何我可以删除它吗?
该片段具有以下布局文件:
<?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)
我看了这篇文章:删除操作栏边框
但考虑到我不想从操作栏中删除边框,我认为它不适用。
我有两个活动,一个应用程序扩展相同的abstract-一个与WebView另一个具有ViewPager与TabLayout和RecyclerView的S -和在这个层面上,我实现“共享”显示/隐藏工具栏与滚动/一扔功能:
app:layout_scrollFlags="scroll|snap|enterAlways"
WebViewToolbar就像RecyclerView在ViewPager(保持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
我想从 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)