What is the default height on Androids TabLayout
Asked Answered
P

2

22

Seems like something that should be easy to find, but it's harder than I thought. What is the default height on the TabLayout in DIPs?

Platypus answered 12/11, 2015 at 11:32 Comment(4)
how to set it to default height, I hate adding lot of custom heights as per different screen resolutionsGlucinum
@ShirishHerwade If you set the height to wrap_content in xml, then it will automatically size to the default height. If you want to explicitly set a height, then set height to 48dp in xml. Using dp sizes it based on screen resolution.If you're trying to set the height dynamically, then you'll have to multiply your height by a float based on screen resolution. You can get the screen resolution using the line: getApplication.getResources().getDisplayMetrics().density;Platypus
Thanks wrap_content worksGlucinum
material.io/guidelines/components/tabs.html#tabs-specsOphthalmoscope
C
45

Material Design guidelines state that this height equals 48dp when You have text or image, and 72dp when You have image and text.

Capitalism answered 12/11, 2015 at 11:44 Comment(1)
it seems like in my side it's different from phone to phone sometimes it's 35dp not sure why this happens.Irresponsible
B
1

its height is "?attr/tabIndicatorHeight"

E.g. you can use this value in an xml file for another view like:

android:layout_marginBottom="?attr/tabIndicatorHeight"

And it will look ok on all devices.

Basile answered 26/5, 2019 at 18:14 Comment(1)
This is marked as deprecated: Instead, set the intrinsic size of the custom drawable provided to the tabIndicator attribute in order to change the indicator height. For example, this can be done by setting the <size> property in a <shape> resource.Dailey

© 2022 - 2024 — McMap. All rights reserved.