Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toolbar title is moving when swapping fragments #304

Closed
mzgreen opened this issue Jul 7, 2016 · 20 comments
Closed

Toolbar title is moving when swapping fragments #304

mzgreen opened this issue Jul 7, 2016 · 20 comments

Comments

@mzgreen
Copy link

mzgreen commented Jul 7, 2016

Hi!

I have one activity and two fragments. Each fragment has it's own Toolbar with different title. When I swap fragments (using transaction.replace) then the title is moving/jumping. In 2.1.0 it's a little better. Movement is a lot less visible but it's still there.
Here is a sample project that reproduces this issue: https://drive.google.com/open?id=0B4aF0Bxe-ecnRjBCaEdIMzMxYVU

It's not using any custom fonts, wrapping Context in attachBaseContext is enough to reproduce this issue.

@mzgreen
Copy link
Author

mzgreen commented Jul 7, 2016

Workaround for this would be to move the Toolbar to the Activity. When only text is changing on the already inflated Toolbar this bug is not present.

@chrisjenx
Copy link
Owner

@mzgreen have you tried the latest support lib, (24.0.0) some users have reported the Jumping around has been fixed.

@mzgreen
Copy link
Author

mzgreen commented Jul 14, 2016

Yes, the sample code actually uses 24.0.0.

@nikita-toropov
Copy link

It worked for me: toolbar.setSubtitle(null);

@mzgreen
Copy link
Author

mzgreen commented Jul 14, 2016

@nik27 where exactly did you put that?
@chrisjenx If setting subtitle to null really helps, do you have an idea why?

@chrisjenx
Copy link
Owner

Setting null probably instantiates the subTitle TextView so it's laid out
correctly. I'll see if I can do something similar

On Thu, 14 Jul 2016 at 14:41 mzgreen [email protected] wrote:

@nik27 https://github.com/Nik27 where exactly did you put that?
@chrisjenx https://github.com/chrisjenx If setting subtitle to null
really helps, do you have an idea why?


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
#304 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABHRsYjw4WPQ0M54_LzKwHhE0LCAnJ4lks5qVjx4gaJpZM4JG067
.

@nikita-toropov
Copy link

@nikita-toropov
Copy link

@chrisjenx
I think this is due to toolbar.setSubtitle(BLANK); in CalligraphyFactory.ToolbarLayoutListener

@TheIronMarx
Copy link

This seems to only periodically occur in my case. Maybe 80% of the time instead of a font change being applied to my Toolbar's title, it will layout an empty subtitle and make no changes to the title itself (aside from pushing it upwards to make room for the subtitle. Oddly, this doesn't occur with my other fragments, just the first one to be inflated on the first activity.

Frustratingly, I'm doing nothing with subtitles at all in my application.

@TheIronMarx
Copy link

Maybe I've narrowed it down. It seems when the first toolbar is being rendered, the bug occurs, but if the app is still in memory or I'm going to another fragment, the title rendering works. Closing the app and reopening works correctly, but closing, swiping from recent apps, then reopening causes the bug.

@TheIronMarx
Copy link

As for @nik27's suggestion about toolbar.setSubtitle(null), this doesn't seem reliable. When I tried doing that during the Toolbar's construction, the subtitle with one space, ToolbarLayoutListener.BLANK, still appeared. However when I did it in the corresponding Fragment's onViewCreated, the BLANK subtitle was gone. With both of these cases, the custom font is never set, so it still isn't a complete solution.

The toolbar.setSubtitle(null) call at different times had different results, but both happen after the attaching Activity's attachBaseContext() has been called. So perhaps there's a race condition occurring?

@thuytrinh
Copy link

This happened quite randomly. Upgrading to support lib v24.x wouldn't resolve the issue. I think I'm gonna put the Toolbar with no title inside a FrameLayout, then put a TextView with left margin on top of the bar. Kinda fake toolbar title anw but that'd at least likely make the issue away.

@Bombo
Copy link

Bombo commented Sep 16, 2016

@chrisjenx
I don't know if this is actually adding to this issue, but here's what I've found:

First of all I also have the Toolbar in my Fragment class and I'm setting the Activity's SupportActionBar in onCreateView of each fragment.
When my activity is first loaded, the title does not have the custom font but the regular one and also displays an empty subtitle (I don't populate the subtitle).
This is because as though the CalligraphyFactory.ToolbarLayoutListener constructor is called (setting the subtitle to BLANK as noted by @nik27) the onGlobalLayout method exits prematurely, because the WeakReference of the Toolbar instance returns null at this point, so the subtitle isn't set to its original value. Subsequently the toolbar renders perfectly fine.

So I don't have a solution, yet, but wanted to add my findings to this. I will take another look on Monday.

Thanks for this nice library, btw. Really makes my life easier! :)

@chrisjenx
Copy link
Owner

Wondering if this fixes it #327

@Bombo
Copy link

Bombo commented Sep 22, 2016

Yes, it appears to, actually. In addition to no "empty" subtitle showing up anymore, the custom font seems to be applied consistently, now. I was counting on the first part being fixed by this, but have to say that I'm a little bit confused about how this fixes the second one. ;)

Although I have to admit that I have troubles reproducing the issues at all with the release version right now. Last week I got the behavior pretty constantly.

@gjsalot
Copy link

gjsalot commented Nov 29, 2016

@chrisjenx @Bombo
#327 does seem to fix the "empty" subtitle issue. However, it does not seem to fix the custom font not being applied consistently.

@mzgreen
Copy link
Author

mzgreen commented Dec 22, 2016

This still doesn't work for me. I'm on support 25.1.0.
Everything seems to be ok at first glance, but if I start switching between 2 fragments back and forth then after couple of trials toolbar stays aligned to top (invisible subtitle?) with Roboto instead of custom font.
Is there any known workaround? Maybe wrapping TextView inside Toolbar would help?

@chrisjenx
Copy link
Owner

chrisjenx commented Dec 22, 2016 via email

@mzgreen
Copy link
Author

mzgreen commented Dec 22, 2016

What do you mean by custom Toolbar? Put TextView inside and not use toolbar's title property or completely custom view instead on toolbar?

@chrisjenx
Copy link
Owner

chrisjenx commented Dec 22, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants