How to set tab height in Android TabLayout?

I have this TabLayout on Android and you want to make the tabs a little more complex than the standard (48dp)

    <android.support.design.widget.TabLayout
            android:id="@+id/contentTabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            style="@style/Theme.Zhaw.TabLayout"
            app:tabMode="fixed"
            app:tabGravity="fill"/>

Here is the Theme.Zhaw.TabLayout style:

<style name="Theme.Zhaw.TabLayout" parent="Widget.Design.TabLayout">
    <item name="tabIndicatorColor">@color/text_white</item>
    <item name="tabIndicatorHeight">4dp</item>
    <item name="tabPaddingStart">6dp</item>
    <item name="tabPaddingEnd">6dp</item>
    <item name="tabBackground">@color/colorPrimary</item>
    <item name="tabTextAppearance">@style/Theme.Zhaw.TabLayoutText</item>
    <item name="tabSelectedTextColor">@color/text_white</item>
</style>

tabIndicatorHeight can set the height of the small indicator (active tab) on the tab. but how can we set the height of the tab itself?

+4
source share
2 answers

set layout_height to dps instead of wrap_content, this may differ in different display sizes, but if you want to dynamically set the height

getApplication.getResources().getDisplayMetrics()

get the current height and calculate the height in accordance with this

+5
source

layout_height wrap_content , ,

  <android.support.design.widget.TabLayout
            android:id="@+id/contentTabs"
            android:layout_width="match_parent"
            android:layout_height="Your Value"
            style="@style/Theme.Zhaw.TabLayout"
            app:tabMode="fixed"
            app:tabGravity="fill"/>
+2

Source: https://habr.com/ru/post/1658816/


All Articles