Reputation: 39
I'm coding a mobile application and I need to find how to get the "appbar" height (which can change from a device to another). I searched a lot but couldn't find any answer. I already did this to get the "action bar" height :
val resources: Resources = this.resources
val resourceId: Int = resources.getIdentifier("navigation_bar_height", "dimen", "android")
val lengthNavBar = if (resourceId > 0) {
resources.getDimensionPixelSize(resourceId)
} else 0
I thought that maybe it would be similar for the action bar, but nothing worked. Just to be clear, to me the app bar is that :
And it can be that depending on the device : (That's why I need a dynamic value)
Thank you in advance!
Upvotes: 0
Views: 354
Reputation: 76769
The first one picture isn't even part of the application, but it's the system UI. One could obtain the value from the rendered component, but the system UI's status-bar's height is rather irrelevant.
The area, where it reads "Accueil", should be ?android:attr/actionBarSize
or android.R.attr.actionBarSize
, which defaults to 56dp
.
Upvotes: 1
Reputation: 19562
That part's called the status bar it's usually 24dp high, but with notched diplays like that one it's at least the height of the notch:
In portrait orientation with no special flags set, the status bar must extend to at least the height of the cutout.
Here's the guidance on dealing with cutouts - basically you probably shouldn't be worrying about the height at all. By default you can just pretend it's not there, if you need to control it and display your own content in there, there are flags you can set. If you do need the value:
Avoid hard-coding the status bar height, as this can lead to overlapping or cut-off content. Where possible, use WindowInsetsCompat to retrieve the status bar height and determine the appropriate padding to apply to your content.
Upvotes: 1