2016-10-25 2 views
4

У меня есть этот TabLayout в Android и хотел сделать вкладки немного heigher, чем по умолчанию (48dp) вКак установить высоту вкладок в Android TabLayout?

<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"/> 

Вот это стиль 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 можно установить высота маленького индикатора (активная вкладка) на вкладке. но как мы можем установить высоту самой вкладки?

+1

просто заменить высоту с андроида: layout_height = "your_height" –

+0

@HRaval java.lang.RuntimeException: Unab le для начала действия ComponentInfo {MainActivity}: android.view.InflateException: двоичная строка XML-файла # 25: двоичная строка XML-файла # 25: вы должны указать атрибут layout_height. – Suisse

ответ

5

установить layout_height в дпс вместо wrap_content это может отличаться в различных размерах дисплея, но если вы хотите установить высоту динамически

getApplication.getResources(). GetDisplayMetrics() получить текущую высоту и вычислить высоту в соответствии с что

2

просто изменить 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"/> 
Смежные вопросы