1

I'm using material library and using a TabLayout with three TabItem. In this TabItem I use icons and I want to make it bigger but I don't know if it's possible to change the icon size.

This is my XML right now:

  <com.google.android.material.tabs.TabLayout
        android:id="@+id/tablayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline6"
        app:tabBackground="@drawable/tab_background_color_selector"
        app:tabIconTint="@color/white"
        app:tabIndicator="@null">

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:icon="@drawable/icon_one"/>

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:icon="@drawable/icon_two"/>

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:icon="@drawable/icon_three"/>

    </com.google.android.material.tabs.TabLayout>
UyerBit
  • 71
  • 6
  • It is possible to give your TabItems completely custom views (in code, rather than xml though). Refer to [this question](https://stackoverflow.com/questions/40896907/can-a-custom-view-be-used-as-a-tabitem) for example. So you basically can increase their size and do much more if you want. – Vucko Mar 04 '21 at 09:12
  • https://stackoverflow.com/a/35372182/5684956 You can use a custom layout for flexible size to tab item – Ashton Yoon Mar 04 '21 at 09:28

1 Answers1

0

You can create your own custom tab layout with a imageView inside it.

Eg: I have named it my_custom_tab.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"
        android:id="@+id/icon"
        android:layout_gravity="center_horizontal" />
</LinearLayout>

And then in your MainActivity class you can do this

View view = getLayoutInflater().inflate(R.layout.my_custom_tab, null);
ImageView icon = view.findViewById(R.id.icon);
icon.setBackgroundResource(R.drawable.your_drawable);
tabLayout.addTab(tabLayout.newTab().setCustomView(view));
REX
  • 139
  • 1
  • 8