0

I want to get this value in AppBar.kt

private val AppBarHeight = 56.dp

I'm using the TopAppBar in a Scaffold and need to know its height, how can I retrieve this value without hard-coding it where I use it? I want to avoid declaring a dimen value for this if possible and measuring the UI element.

BobDidley
  • 53
  • 6
  • What is the use-case? – Abhimanyu Jun 22 '23 at 23:21
  • 1
    If you don't mind triggering recomposition you can get it via Modifier.onSizeChanged/onGloballyPositioned/onPlaced but triggering recomposition to set another composable might trigger recomposition. And if you don't want to trigger recomposition you can check [this thread](https://stackoverflow.com/questions/73354911/how-to-get-exact-size-without-recomposition) – Thracian Jun 23 '23 at 11:34

1 Answers1

1

With a quick look at the code I don't think this is possible. So, the height of the AppBar is set like this: enter image description here

but the `TopAppBar_Tokens are an internal object: enter image description here

Eliza Camber
  • 1,536
  • 1
  • 13
  • 21