CollapsingToolbarLayout setTitle()不再起作用 [英] CollapsingToolbarLayout setTitle() not working anymore

查看:98
本文介绍了CollapsingToolbarLayout setTitle()不再起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CollapsingToolbarLayout中的setTitle()方法已经存在一些错误(例如仅在滚动后显示,已在v22.2.1中修复).

The setTitle() method from CollapsingToolbarLayout had some bugs already (like showing only after a scroll, fixed in v22.2.1).

今天我更新到了v23.0.0,它根本无法正常工作,就像没有显示标题一样.通过延迟多次调用它,我可以看到有时有标题,但是它确实不可靠(例如,您切换到另一个片段,然后又回到第一个片段,就不再有标题了.)

Today I updated to v23.0.0, and it is simply not working, like no title is shown. By calling it multiple times with a delay, I can see that sometimes the title is there, but it is really not reliable (like, you switch to another fragment, then back to the first, and there's no title anymore).

我发现有一个新属性,app:titleEnabledCollapsingToolbarLayout.setTitleEnabled(boolean).我都将其设置为true,但实际上并没有任何改变.

I found there's a new attribute, app:titleEnabled or CollapsingToolbarLayout.setTitleEnabled(boolean). I have set both to true, but it doesn't change anything actually.

你们中有人有同样的行为吗?

Is any of you experiencing the same behavior?

我想知道市场上有多少应用程序真正在使用这个设计库,它从第一版开始就存在很多错误,并且没有得到改善.

I wonder how many apps out there in the market are really using this Design Library, it has been full of bugs from the very first release and is not getting better.

经过进一步测试,似乎(我不确定100%肯定)它已连接到新的AppBarLayout.setExpanded() api.

With further testing, it seems (I'm not 100% sure) it is connected to the new AppBarLayout.setExpanded() api.

如果我打电话:

collapsingToolbar.setTitle("title");

可以,但是如果我打电话

it works, but if I call

collapsingToolbar.setTitle("title");
appbarLayout.setExpanded(true, true);
//OR
appbarLayout.setExpanded(true, true);
collapsingToolbar.setTitle("title");

没有-没有标题显示.与setExpanded(false, true)相同,i. e.试图折叠工具栏.

it doesn't - no title shown. Same with setExpanded(false, true), i. e. trying to collapse the toolbar.

嗯,不.即使我从不调用abl.setExpanded()app:expanded,也存在此问题.另外,我们现在使用的是v23.0.1,目前尚未修复.似乎只有少数几个人正在经历它,因为我在这里也没有在正式的错误列表中找不到任何东西.我在此处.

Well, no. The issue is present even when I never call abl.setExpanded() or app:expanded. Also, we're on v23.0.1 now and this still has not been fixed. Looks like only a few of us are experiencing it, because I couldn't find anything here nor in the official bug list. I filed a bug here.

推荐答案

由于AppBarLayout的布局高度太小,因此标题未显示.我的身高为110dp,这在v22.2.1中有效.升级到v23.0.0后,我必须将高度至少更改为 125dp ,以便显示标题.无需使用新的属性或方法调用.这是我的布局:

The title doesn't show because the layout height of the AppBarLayout is too small. I had a height of 110dp and this worked in v22.2.1. After I upgraded to v23.0.0, I had to change the height to at least 125dp in order for the title to show. No need to use the new attribute or method calls. Here is my layout:

<android.support.design.widget.CoordinatorLayout
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.AppBarLayout
    android:id="@+id/appbar"
    android:layout_height="125dp"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbarLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:expandedTitleTextAppearance="@style/ExpandedAppBarTitle"
        app:expandedTitleMarginStart="14dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

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

<android.support.v7.widget.RecyclerView android:id="@android:id/list"
                                        xmlns:android="http://schemas.android.com/apk/res/android"
                                        android:layout_width="match_parent"
                                        android:layout_height="match_parent"
                                        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/addbtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
    app:borderWidth="0dp"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_add" />

这篇关于CollapsingToolbarLayout setTitle()不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆