CollapsingToolbarLayout setTitle() does not update unless collapsed

前端 未结 3 1496
既然无缘
既然无缘 2020-12-01 10:55

With the new Design Library, we\'re supposed to set the toolbar title on the CollapsingToolbarLayout, not the Toolbar itself(at least when using th

3条回答
  •  我在风中等你
    2020-12-01 11:33

    EDIT: 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.

    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.

    This is what I have

    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);
    }
    

    in styles.xml I have

    
    
    
    
    
    
    
    

    Happy Coding.

提交回复
热议问题