CollapsingToolbarLayout的setTitle()不更新,除非崩溃 [英] CollapsingToolbarLayout setTitle() does not update unless collapsed

本文介绍了CollapsingToolbarLayout的setTitle()不更新,除非崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着新的设计库,我们应该设置在 Col​​lapsingToolbarLayout ,而不是工具栏本身(至少当使用压扁栏)。但的setTitle()只更新了以下具体情况标题:

With the new Design Library, we're supposed to set the toolbar title on the CollapsingToolbarLayout, not the Toolbar itself(at least when using the collapsing toolbar). But setTitle() only updates the title in the following specific circumstances:

1)当 Col​​lapsingToolbarLayout 没有标题但

2)目前的 Col​​lapsingToolbarLayout 变成完全崩溃了。

2) At the moment the CollapsingToolbarLayout becomes fully collapsed

3)目前的 Col​​lapsingToolbarLayout 开始展开

什么实际上,我要做的是使标题变成的EditText 当完全展开,允许用户给他/她的角色名字,然后显示作为标题。我试图通过调用强制问题 无效() requestLayout(),以及这两者对 Col​​lapsingToolbarLayout <那些方法/ code>的孩子。没有效果。

What I'm actually trying to do is make the title become an EditText when fully expanded, allowing the user to give his/her character a name, which then displays as the title. I've tried to force the issue by calling invalidate() or requestLayout(), as well as both of those methods on CollapsingToolbarLayout's children. No effect.

任何想法?

推荐答案

编辑:该解决方案不再需要。漏洞修复 v22.2.1

This solution is no longer needed. bug fixed in v22.2.1

我没有想见好就收链接所以这里是完整的解决方案。

I didnt want to just leave links so here is the full solution.

该错误是因为code处理的可折叠式标题只更新实际的标题,如果当前标题为空或文本大小发生了变化。解决方法是更改​​标题文字大小,然后将它改回来。我用0.5 SP所以​​有没有太多的跳跃。改变文本尺寸迫使要更新的文本并且没有闪烁。只是微微的文字大小的变化。

The bug occurs because the code to handle the collapsable title only updates the actual title if the current title is null or the text size has changed. The workaround is to change the title text size and then change it back. I used 0.5 sp so there was not too much of a jump. Changing the text size forces the text to be updated and there is no flicker. just a slight text size change.

这是我

private void setCollapsingToolbarLayoutTitle(String title) {
    mCollapsingToolbarLayout.setTitle(title);
    mCollapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.ExpandedAppBar);
    mCollapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.CollapsedAppBar);
    mCollapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.ExpandedAppBarPlus1);
    mCollapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.CollapsedAppBarPlus1);
}

在styles.xml我有

in styles.xml I have

<style name="ExpandedAppBar" parent="@android:style/TextAppearance.Medium">
    <item name="android:textSize">28sp</item>
    <item name="android:textColor">#000</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="CollapsedAppBar" parent="@android:style/TextAppearance.Medium">
    <item name="android:textSize">24sp</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:textStyle">normal</item>
</style>

<style name="ExpandedAppBarPlus1" parent="@android:style/TextAppearance.Medium">
    <item name="android:textSize">28.5sp</item>
    <item name="android:textColor">#000</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="CollapsedAppBarPlus1" parent="@android:style/TextAppearance.Medium">
    <item name="android:textSize">24.5sp</item>
    <item name="android:textColor">@color/white</item>
    <item name="android:textStyle">normal</item>
</style>

编码快乐。

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

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