I had the same problem - the icon in the tab had been to small and there was no way to make it bigger. I found an alternative of Özer Özcans answer the easiest. The key is the statement android:layout="@layout/your_custom_layout". One can make 3 different custom layouts for 3 different tabs. That way -everything- can be done in xml. To make it easy use a "shared" layout for your first tests. Replicate to custom_layout2,3 and
just change the icon drawable names. This offers full control.
The only thing that would -not- work is the yellow circle counter in Denny´s question, as this is dynamic. If you need that Özers answer is again the best.
Here are the xml snippets:
<com.google.android.material.tabs.TabLayout
android:id="@+id/maintab"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="0dp"
android:layout_width="match_parent"
android:layout_height="65dp"
app:tabBackground="@drawable/tab_selector">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/tab_layout"
/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/tab_layout2"
/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout="@layout/tab_layout3"
/>
</com.google.android.material.tabs.TabLayout>
Followed by one of the 3 tab_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="65dp"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/mytabIcon"
android:layout_width="100dp"
android:layout_height="60dp"
android:scaleX= "0.5"
android:scaleY= "0.5"
android:src="@drawable/basis_tab"
android:layout_centerVertical="true"
app:tint="@color/whitecream" />
Scaling the image worked nicely with scaleX and Y then.
Interestingly the Tablayout class did manage to distribute space equally in 1/3 of screenwidth, and also kept the aspect ratio of the icons. This is excellent since my drawables are big images (so they could explode the layout), while i set a fixed dp width in
android:layout_width="100dp". The Tablayout class nicely expands this to the full screen width (which can be variable).
Obviously noone wants distorted icons. I also tested what Tablayout does when the width is to small - it then starts to scale down the tab icon.