[英]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.