Hi guys is there going to be a way to style the Ti...
# compose
p
Hi guys is there going to be a way to style the Titles on MediumAppBar ? I want to style them differently
at least you could expose TwoRowsTopAppBar so we could use it directly
s
While I don’t have strong opinions regarding if this would fit this API or not. I can just say to fix your issue now, you should just wrap your title composable with a
Copy code
ProvideTextStyle(value = yourTextStyle) {}
since that’s all it does under the hood anyway.
p
but how do you style them diferently?
this bar has 2 titles I want to style them diferently
s
Actually, how do you provide the two titles? It only has a single
title
slot.
p
that's ok it's a composable but the styles I can't access them
s
But then inside of the
title: @Composable () -> Unit
, can't you provide different styles directly?
s
The top bar is only for icons and the navigation item though, not for two different texts

https://developer.android.com/images/reference/androidx/compose/material3/medium-top-app-bar.png

p
but then is style for boths
I want to have style when it bar is minimized
and one when is expanded
that's what this 2 parameters are for
Copy code
titleTextStyle = MaterialTheme.typography.fromToken(TopAppBarMediumTokens.HeadlineFont),
smallTitleTextStyle = MaterialTheme.typography.fromToken(TopAppBarSmallTokens.HeadlineFont),
s
Ahh, gotcha, that's what you mean with “two titles”. Sorry, I thought you mean like a title and a subttle in a column or something.
p
That would be ok
s
Yeah, this seems trickier. I guess the boring answer is “material is opinionated”, but it would be nice if
TwoRowsTopAppBar
perhaps could be exposed, yeah.
p
I mean if you look to the implementation is the MediumTopAppbar is just delegating
but hiding the access
s
Is there a way for you to listen to the state (expanded or “collapsed”) and change the style based on that?
s
Yeah what Sindre is saying regarding opinionated decisions. I doubt they want you to have two different styles for the two different states of the top app bar. You can always copy the source of TwoRowsAppBar yourself into your own project. It’s probably private due to its API likely to change and/or they don’t want to make the API surface harder to deal with.
p
I think so but.... WHYYYYY
Life is hard sometimes 🙂
guess I need to listen to states and then do it myself
s
I’d personally just take the source of
TwoRowsTopAppBar
and paste it in my project. And make a FR to see what the ui team thinks regarding exposing this directly somehow
p
it's more complicated then that. The code is blocked so you will end up copying alot of code
Copy code
TopAppBarLayout(
is also private for example
s
Ah of course, that can happen too. I’ve successfully copy pasted other times I’ve had similar issues, but it’s not always a solution unfortunately
p
I think here is too much code and you will end up copy pasting and mataining it too
so for my personal view is if any Googler can help to expose them or make some of them public
like the TwoRowsTopAppBar
s
Yeap, don’t do it in this case, seek alternatives first then. And make sure to make an issue and link it back here so that we can +1 it to see what they will think of the idea.
p
I never opened an issue 😞
can you help
or you know where ?
s
Yes here is where you can do that https://issuetracker.google.com/issues/new?component=742043&template=1590761 And you can pick the correct component, this time I’m linking you directly to Material, but for some other bug you may want to target a different component instead
p
do you know if there is a way to know if the appbar is cloapsed?
s
No I am afraid I don’t. I haven’t used M3 yet.
s
I guess you'd have to check with the scroll behaviour thingy.
p
done issue created
Do you guys know if there is a way to override the Material properties ?
I have a custom Theme
but for this case maybe we could use somehow a way to override this Properties ?