如何显示工具栏的标志,图标,标题,副标题裹在CollapsingToolbarLayout什么时候? [英] How to show Toolbar's logo, icon, title, subtitle when wrapped in a CollapsingToolbarLayout?

本文介绍了如何显示工具栏的标志,图标,标题,副标题裹在CollapsingToolbarLayout什么时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

支持Android设计库发布之后,我想实现的是类似的 Twitter的个人资料页面的效果,其中工具栏标题字幕可以为屏幕滚动垂直变化。所以我试图用 CoordinatorLayout AppBarLayout Col​​lapsingToolbarLayout 工具栏支持Android设计库,以达到这种效果。一切都按预期不同的是工具栏的内容无法显示或改变我想要的。我一直想显示 collapseIcon navigationIcon 标题 工具栏字幕,但他们并没有显示出来,尽管我已经将它们的布局和编程。正如博客说,

After Android Support Design Library was released, I wanted to implement an effect like a page of Twitter Profile, in which Toolbar's title and subtitle could be changed as screen scrolled vertically. So I tried to use CoordinatorLayout, AppBarLayout, CollapsingToolbarLayout and Toolbar from Android Support Design Library to achieve this effect. Everything worked as expected except that Toolbar's content couldn't be showed or changed as I wanted. I should have been wanting to display collapseIcon, navigationIcon, title, subtitle of Toolbar, but they didn't show up even though I had set them in the layout and programmatically. Just as the blog said,

请注意,在这种情况下,你应该调用的setTitle()上的   CollapsingToolbarLayout,而不是工具栏上的本身。

Note that in those cases, you should call setTitle() on the CollapsingToolbarLayout, rather than on the Toolbar itself.

如果您已经检查了<一href="https://developer.android.com/reference/android/support/design/widget/CollapsingToolbarLayout.html"相对=nofollow> DOC ,你会发现 Col​​lapsingToolbarLayout 只专注于标题设置,但也无可奈何 collapseIcon navigationIcon 字幕

If you have checked the doc, you would find out CollapsingToolbarLayout only focus on settings of title, but can do nothing about collapseIcon, navigationIcon and subtitle.

所以,能不能有人告诉我如何达到这种效果通过工具栏 Col​​lapsingToolbarLayout ?如果他们不能,那还有什么其他的事情可能是什么?任何人有任何想法,这事吗?

So could someone tell me how to achieve this effect by Toolbar and CollapsingToolbarLayout? If they couldn't be able, then what other things could be? Anybody has any ideas about this?

任何提示将AP preciated。先谢谢了。

Any tips will be appreciated. Thanks in advance.

推荐答案

这个问题已经提交的此处作为一个bug。我亲身经历了这与我的应用程序之一。设置 TOPMARGIN 为工具栏为我工作。正如有人评论的bug报告,这里是修复,从问题的报告功能。

This issue was reported here as a bug. I have personally experienced this with one of my apps. Setting the topMargin for the toolbar works for me. As somebody commented on the bug report, here is the fix, as a function from the issue report.

private void fixApi21ToolBarBug(Toolbar toolbar){
    if(Build.VERSION.SDK_INT!=21) return; //only on api 21
    final int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    final int result = (resourceId > 0) ? getResources().getDimensionPixelSize(resourceId) * 2 : 0;
    final CollapsingToolbarLayout.LayoutParams params = (CollapsingToolbarLayout.LayoutParams) toolbar.getLayoutParams();
    params.topMargin -= result;
    toolbar.setLayoutParams(params);
}

在这里查看结果。

See the result here.

这篇关于如何显示工具栏的标志,图标,标题,副标题裹在CollapsingToolbarLayout什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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