layout/tab_header_badge.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayoutTabHeader"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageViewTabHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_bell" />
<TextView
android:id="@+id/textViewActiveAlarmBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/imageViewTabHeader"
android:text="1"
android:textColor="@color/accent" />
</RelativeLayout>
viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
viewPagerAdapter.addFragment(moreFragment); // 3
viewPagerAdapter.addFragment(alarmHistoryFragment); // 2
viewPagerAdapter.addFragment(activeAlarmsFragment); // 1
viewPagerAdapter.addFragment(mainFragment); // 0
viewPagerMain.setAdapter(viewPagerAdapter);
viewPagerMain.setCurrentItem(3); // set default view on open
tabLayoutMain.setupWithViewPager(viewPagerMain);
tabLayoutMain.getTabAt(3).setIcon(R.drawable.ic_home);
//tabLayoutMain.getTabAt(2).setIcon(R.drawable.ic_bell);
tabLayoutMain.getTabAt(1).setIcon(R.drawable.ic_envelope_open);
tabLayoutMain.getTabAt(0).setIcon(R.drawable.ic_bars);
View tabHeader = LayoutInflater.from(this).inflate(R.layout.tab_header_badge, null);
TextView textViewBadge = tabHeader.findViewById(R.id.textViewActiveAlarmBadge);
textViewBadge.setText("10");
tabLayoutMain.getTabAt(2).setCustomView(tabHeader);
// endregion
References
https://mobikul.com/make-custom-tabs-icons-android/
https://stackoverflow.com/questions/41530141/how-to-show-notification-counter-in-a-tablayout
https://stackoverflow.com/questions/43266079/how-to-add-badge-to-android-tablayout