简体   繁体   English

CollapsingToolbarLayout折叠时未显示工具栏标题

[英]Toolbar Title not showing when CollapsingToolbarLayout collapsed

In my MainActivity I have a CollapsingToolbarLayout . 在我的MainActivity中,我有一个CollapsingToolbarLayout By default the toolbar it is expanded. 默认情况下,工具栏会展开。 But I want it to be collapsed. 但我希望它崩溃。 So as suggested in a StackOverflow question I used the AppBarLayout class to make it collapsed by default, using this code: 因此,正如StackOverflow问题中所建议的那样,我使用AppBarLayout类使用以下代码将其默认折叠:

AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);
appBarLayout.setExpanded(false);

This works fine, excepting one thing. 除一件事外,这工作正常。 The toolbar title doesn't show up anymore, not even if I expand and collapse the toolbar manually. 即使我手动展开和折叠工具栏,也不会显示工具栏标题。 If I do not collapse the toolbar by default then the title is showing, but if I change the imageView from the CollapsingToolbarLayout then the title dissapear. 如果默认情况下我不折叠工具栏,则显示标题,但是如果我从CollapsingToolbarLayout更改imageView ,则该标题消失。

Here is my CollapsingToolbarLayout code: 这是我的CollapsingToolbarLayout代码:

ViewCompat.setTransitionName(findViewById(R.id.app_bar_layout), EXTRA_IMAGE);
CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsingToolbarLayout.setTitle("Search Activity");
collapsingToolbarLayout.setExpandedTitleColor(getResources().getColor(android.R.color.transparent));
collapsingToolbarLayout.setCollapsedTitleGravity(Gravity.START);

My question is: Am I not setting up the title correctly or am I not collapsing the toolbar in the right way? 我的问题是:我是否正确设置标题或我没有以正确的方式折叠工具栏? how can I fix this? 我怎样才能解决这个问题?

Thank you for your help! 谢谢您的帮助!

It seems to be a bug of support-v4, appcompat-v7 v24.2.0 as related here . 似乎是support-v4, appcompat-v7 v24.2.0的错误support-v4, appcompat-v7 v24.2.0 处所示

Probably the next release will fix the issue. 下一个版本可能会解决该问题。

I fixed it by temporally downgrading to v24.1.1 the following libraries in build.gradle : 我固定它通过在时间上降级到v24.1.1在以下库build.gradle

compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:appcompat-v7:24.1.1'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CollapsingToolbarLayout折叠时显示标题损坏 - CollapsingToolbarLayout showing broken title when collapsed CollapsingToolbarLayout中的工具栏,工具栏标题未显示 - Toolbar inside CollapsingToolbarLayout, Toolbar title not showing 当CollapsingToolbarLayout折叠时,工具栏HOME不起作用 - Toolbar HOME not working when CollapsingToolbarLayout collapsed collapsingToolbarLayout仅在折叠时设置标题 - collapsingToolbarLayout set title only when collapsed 折叠时未设置片段标题中的CollapsingToolbarLayout - CollapsingToolbarLayout in Fragment title not set when collapsed 最初折叠ActionBarLayout时,CollapsingToolbarLayout标题会消失 - CollapsingToolbarLayout title disappears when ActionBarLayout is initially collapsed 仅在折叠时显示 CollapsingToolbarLayout 标题 - Show CollapsingToolbarLayout title only when collapsed 当CollapsingToolbarLayout折叠时,锚定图像会被工具栏重叠 - Anchor image gets overlapped by toolbar when CollapsingToolbarLayout is collapsed 未折叠时,工具栏的某些部分在CollapsingToolbarLayout的ImageView上可见 - When not collapsed some part of the the toolbar is visible over the ImageView of CollapsingToolbarLayout 如何将RecyclerView放在CollapsingToolbarLayout下面并在Android中折叠时响应工具栏? - How to put RecyclerView below CollapsingToolbarLayout and responsive to toolbar when collapsed in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM