如何在Android的TabLayout中设置标签的高度? [英] How can I set the height of tabs in Android a TabLayout?

查看:1326
本文介绍了如何在Android的TabLayout中设置标签的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android中具有此TabLayout,并希望使这些标签比默认值(48dp)高一点

I Have this TabLayout in Android and wanted to make the tabs a little heigher than the default (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"/>

这是样式主题.Zhaw.TabLayout:

Here is the Style Theme.Zhaw.TabLayout:

<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可以设置选项卡中小指示器(活动选项卡)的高度.但是我们如何设置标签本身的高度?

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

推荐答案

在dps中设置layout_height而不是wrap_content,这在不同的显示尺寸上可能会有所不同,但是如果您想动态设置高度

set a layout_height in dps instead of wrap_content this could differ in different display sizes but if you wanna set a height dynamically

getApplication.getResources().getDisplayMetrics()

获取您当前的身高,并根据该身高计算身高

get your current height and calculate the height according to that

这篇关于如何在Android的TabLayout中设置标签的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆