标签: android-appbarlayout

CollapsingToolbarLayout:自定义contentScrim类似于Facebook

我想为我创建一个自定义contentScrim collapsingToolbarLayout.我的collapsingToolbarLayout有一个imageview内部.当它滚动时,理论上,imageview被认为是淡出,我的稀松布颜色被假定为淡入.

我们都知道我们可以制作这样的稀松布:

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:contentScrim="?attr/colorPrimary"
                android:background="@color/white"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleMarginEnd="64dp"
                android:fitsSystemWindows="true"
                app:expandedTitleTextAppearance="@color/transparent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                >
Run Code Online (Sandbox Code Playgroud)

然而,当您在屏幕上滚动3/4时,Android默认稀松布似乎才开始工作.在此之前,imageview仍然完整显示.此外,当你达到屏幕的3/4时,平纹棉布开始并自动将collapsingtoolbarlayout的颜色更改为你的稀松布颜色:

纱幕

当你向上滚动3/4并且在我们到达之前,它没有让它完全充满屏幕toolbar,我希望它轻轻地褪色,直到你滚动到toolbar.

如果您想查看我想要创建的效果的示例,请查看Facebook应用程序.当collapsingToolbarLayout完全展开时,这是Facebook应用程序:

在此输入图像描述

滚动到大约3/4时,collapsingToolbarLayout有一个褪色的蓝色,蓝色不完全饱和:

在此输入图像描述

所以我在我的内部创建了以下内容collapsingToolbarLayout:

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

        <com.customshapes.SquareImageView
            android:id="@+id/backdrop"
            android:contentDescription="@string/photo"
            android:transitionName="@string/transition"
            android:layout_width="match_parent"
            android:layout_height="240dp"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            />

        <com.customshapes.SquareImageView
            android:id="@+id/fading_backdrop"
            android:layout_width="match_parent"
            android:background="?attr/colorPrimary"
            android:layout_height="240dp"
            android:alpha="0"
            android:fitsSystemWindows="true"
            />

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

framelayout包含背景imageview,该背景保存在我的collapsingToolbarLayout中显示的图片,在它前面是一个imageview,它只保存'scrimColor'?attr/colorPrimary,其alpha值为0,这样背景imageview就会闪耀.

然后我实现了appBarLayout的onOffsetChangedListener:

@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {

    fading_backdrop.setImageAlpha(verticalOffset);
    fading_backdrop.invalidate();
}
Run Code Online (Sandbox Code Playgroud)

我们设置了fading_backdrop的alpha值,以便在向上滚动时显示.我正在努力创造一个人造稀松布.

但是,这似乎不能正常工作.运行此代码时,根本没有淡入淡出.有谁知道我做错了什么?

android android-collapsingtoolbarlayout android-appbarlayout

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

如何减少jetpack中导航图标和标题之间的水平空间组成“TopAppBar”?

我正在 jetpack compose 中制作一个应用程序栏,但导航图标和标题之间存在间距问题。

这是我的撰写功能:

@Composable
fun DetailsAppBar(coin: Coin, backAction: () -> Unit) {
    TopAppBar(
        navigationIcon = {
            IconButton(onClick = { backAction() }) {
                Icon(
                    imageVector = Icons.Filled.ArrowBack,
                    contentDescription = null
                )
            }
        },
        title = { Text(text = "${coin.rank}. ${coin.name} (${coin.symbol})") }
    )
}
Run Code Online (Sandbox Code Playgroud)

这是我的预览功能:

@Composable
@Preview
fun DetailsAppBarPreview() {
    val bitcoin = Coin(
        id = "",
        isActive = true,
        name = "Bitcoin",
        rank = 1,
        symbol = "BTC"
    )
    DetailsAppBar(coin = bitcoin, backAction = {})
}
Run Code Online (Sandbox Code Playgroud)

这是我的撰写功能的视觉预览: 自定义应用栏预览

这是我要减少的空间: …

android android-appbarlayout android-jetpack-compose

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

在嵌套片段中使用recyclerView的AppBarLayout

由于图像总是比文字更好,我向您呈现我当前的布局.

工具栏/选项卡位于带有viewPager的activity.xml中,recyclelerView位于viewPager中的片段内.因此,您可以向右/向左滑动以查看其他内容.

我的问题是我希望AppBarLayout在其滚动行为中绑定到第一个片段中的recyclerView,而不是其他片段.

在下面的代码中,我做了这个绑定,但它不起作用,因为recyclerView无法识别外部布局中的AppBarLayout .你有解决方法吗?

活动代码:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
    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.support.v7.widget.Toolbar
            android:id="@+id/toolbar_main"
            android:layout_width="match_parent"
            /* pretty stuff */
            app:layout_scrollFlags="scroll|enterAlways">

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                /* pretty stuff */ />

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

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

    <android.support.v4.view.ViewPager
        android:id="@+id/main_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.SupportFloatingActionsMenu
           ...>
           /* Code for a fancy fab w/ menu */

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

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

对于包含recyclerView的片段:

<android.support.design.widget.CoordinatorLayout
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"
    tools:context="com.insa.burnd.view.MainActivity.NewsfeedFragment"
    android:id="@+id/fragment_newsfeed">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

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

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

android android-fragments androiddesignsupport android-appbarlayout

9
推荐指数
2
解决办法
6432
查看次数

CoordinatorLayout与工具栏和片段

我正在使用下面的布局,其中的CoordinatorLayout内部AppBarLayout(包含ToolbarTabLayout内部)和占位符RelativeLayout,所以我可以在其上添加和替换片段.

我遇到了边距错误,我在RelativeLayout上添加的碎片将总是超出屏幕底部(与AppBarLayout高度大小相似的数量),我尝试将它的高度设置为wrap_contentmatch_parent,在这两种情况下它太过分了.

如果我app:layout_behavior="@string/appbar_scrolling_view_behavior"RelativeLayout顶部移除它将在其下AppBarLayout也不是所希望的结果.

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

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_content"
        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/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_scrollFlags="scroll|enterAlways" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                app:tabIndicatorHeight="4dp"
                app:tabIndicatorColor="#ffffff"
                app:tabMode="scrollable"
                android:visibility="gone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

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


        <RelativeLayout
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:id="@+id/main_fragment_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>


       <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end|bottom"
            android:layout_margin="20dp"
            android:src="@drawable/ic_done" />


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

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:layout_gravity="start" …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-design-library android-coordinatorlayout android-appbarlayout

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

Android AppBarLayout推送ViewPager

我有下面的xml文件有1)工具栏2)TabLayout 3)自定义视图和4)ViewPager.当我把Toolbar,TabLayout,Custom View里面AppBarLayout,它推动ViewPager下来,就像这样:

在此输入图像描述

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"
    android:id="@+id/feed_coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_tool_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleTextAppearance="@style/Widget.AppCompat.ActionBar.TabText"
            app:layout_scrollFlags="scroll|enterAlways"
            app:statusBarScrim="?attr/colorAccent">


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar_alt"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/primary_color"
                android:minHeight="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:layout_collapseMode="none"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">


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

        <android.support.design.widget.TabLayout
            android:id="@+id/feed_sliding_tabs_alt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed"
            app:tabSelectedTextColor="@color/accent_color"
            app:tabTextColor="@color/accent_color_per_70" />

        <LinearLayout
            android:id="@+id/activity_feed_fl_canli_skor"
            android:layout_width="match_parent"
            android:layout_height="52dp"
            android:background="@drawable/mac_back"
            android:orientation="vertical">


        </LinearLayout>

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

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


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floating_action_button"
        android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-viewpager android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout

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

NestedScrollView与webView仅滚动NestedScrollView

下面是我的代码,用于处理我的应用程序actionBar/toolbar/tabBar和nestedScrollView以及其中的ViewPager(webView)的正确行为.ViewPager基本上是一个普通的webView.

除了我的ViewPager无法垂直滚动外,一切正常.仅滚动NestedScrollView.我想要与Facebook应用程序相同的行为,如果您滚动新闻源(webView),tabBar会垂直移动工具栏.

<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"
    tools:context=".ui.activity.FragmentContainer"
    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"
                    app:theme="@style/M.Toolbar"
                    app:popupTheme="@style/M.Toolbar.PopupTheme"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_scrollFlags="scroll|enterAlways"
                    >
                </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"
            android:visibility="gone"
            android:background="@color/background"
            app:background="@color/background"
            />

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

    <android.support.v4.widget.NestedScrollView
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:background="@android:color/transparent"
        android:fillViewport="true"
        >

    <com.m.ui.util.EdgeScrollViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:visibility="visible"
        >

    </com.m.ui.util.EdgeScrollViewPager>

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

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

所以为了能够滚动我的viewPager(webView),我添加了一个扩展webView的新类:

公共类TouchyWebView扩展WebView {

    public TouchyWebView(Context context) {
        super(context);
    }

    public TouchyWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public TouchyWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle); …
Run Code Online (Sandbox Code Playgroud)

android-scrollview android-viewpager android-appbarlayout android-nestedscrollview

9
推荐指数
3
解决办法
3403
查看次数

如何在协调器布局中添加下拉刷新

我有一个AppBarRecyclerViewin CoordiantorLayout。SwipeToRefresh 必须全屏显示,但RecyclerView不能向下滚动。

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="128dp"/>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

类

如何在没有库的协调器布局中添加全屏下拉刷新。

android swiperefreshlayout android-recyclerview android-coordinatorlayout android-appbarlayout

9
推荐指数
3
解决办法
1550
查看次数

Material Design 3 顶部应用栏没有阴影。如何启用它?

新的“Material Design 3 顶部应用栏”文档称他们摆脱了投影。我怎样才能启用它?在 Toolbar 或 AppBar 上设置高度根本不起作用。 在此输入图像描述

android material-design android-toolbar android-appbarlayout material-you

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

Flutter/Material 3:AppBar 忽略图标主题

在我的应用程序栏中,标题显示为白色文本,但图标是深灰色或其他颜色。我也想让图标变成白色。

但图标主题中的颜色没有任何效果!

直接添加到 AppBar 时不会...

Scaffold(
  appBar: AppBar(automaticallyImplyLeading: false,
      actionsIconTheme: IconThemeData(color: Colors.white),
      iconTheme: IconThemeData(color: Colors.white),

Run Code Online (Sandbox Code Playgroud)

而且也不在主题中...

appBarTheme: AppBarTheme(
    backgroundColor: Colors.blue,
    foregroundColor: Colors.white,
    actionsIconTheme: IconThemeData(color: Colors.white),
    iconTheme: IconThemeData(color: Colors.white),

),

Run Code Online (Sandbox Code Playgroud)

我想让主题发挥作用!无法在图标上单独设置颜色。

我究竟做错了什么?Material 3 真的准备好投入生产了吗?

谢谢!

注意:这是材料 3 的问题!在材质 2 中,一切都按预期进行!

android-appbarlayout flutter flutter-appbar flutter-theme material3

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

ListView嵌套在API <21上滚动

标题很清楚.我有这个布局:

_________________
|_______________| <- Toolbar    
|___|___|___|___| <- Tablayout
|               |
|               |
|   ViewPager   |
|               |
|_______________|
Run Code Online (Sandbox Code Playgroud)

工具栏和tablayout都在一个内部AppBarLayout,所以我可以使用滚动标记来隐藏工具栏向上滚动.问题是这只适用于嵌套滚动支持的视图.大多数标签 - 我的意思是,大多数页面 - 是support.v4.NestedScrollViews,所以这是可以的; 其他人(并且需要)ListView.

从Lollipop开始,我可以简单地添加android:nestedScrollingEnabled="true"到列表视图,并且工具栏在滚动时正确隐藏.

但是,在API <21上,没有这样的属性,工具栏也不会隐藏.更重要的是,列表中的最后一项是隐藏的,因为有一些测量错误CoordinatorLayout:listview就好像它有工具栏当前占用的空间一样.

解决方案:

  • 切换到RecyclerView,它支持嵌套滚动:我不能,因为我需要使用只适用于适配器视图的外部库适配器,并且我无法替换(即,ParseQueryAdapter);

  • 扩展ListView和实现嵌套滚动:似乎很复杂;

  • 扩展ListView并实现一些解决方法,例如测量东西以避免最后一项问题或(和)自定义行为以使工具栏隐藏:似乎也很复杂;

  • 使用一些布局技巧:找不到.

有帮助吗?

例如,我(拼命)尝试:

<android.support.v4.widget.NestedScrollView
    android:nestedScrollingEnabled="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ListView>

</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

但是这种方式ListView并没有被列为match_parent.我得到一个小高度的小视图,页面的其余部分是空的.

android android-listview android-support-library android-design-library android-appbarlayout

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