I'm trying to implement tabslayout with text and icons above. The desired output is this
But im getting this output
All those icons have changed color, i'm setting the title and icon programmatically. Code:
class HomePage : BaseActivity() {
private lateinit var binding: ActivityHomePageBinding
private lateinit var viewpager: ViewPager2
private val fragmentList = arrayListOf(FoodFragment(),ExerciseFragment(),MedicineFragment(),MoodFragment(),NotesFragment())
private val tabTitles = arrayListOf("Food","Exercise","Medicine","Mood","Notes")
private val tabIcons = arrayListOf(R.drawable.ic_food,R.drawable.ic_exercise,R.drawable.ic_medicine,R.drawable.ic_mood,R.drawable.ic_notes)
private lateinit var customPagerAdapter: CustomPagerAdapter
private lateinit var tablayout: TabLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_home_page)
initUI()
}
private fun initUI(){
val bottomSheetDialog = BottomSheetDialog(this)
val bottomSheetView = LayoutInflater.from(this).inflate(R.layout.bottom_modal_sheet,
findViewById<ConstraintLayout>(R.id.BMS)
)
bottomSheetDialog.setContentView(bottomSheetView)
viewpager = bottomSheetView.findViewById(R.id.BMS_viewpager)
tablayout = bottomSheetView.findViewById(R.id.BMS_tab_layout)
customPagerAdapter = CustomPagerAdapter(fragmentList,this)
viewpager.adapter = customPagerAdapter
TabLayoutMediator(tablayout, viewpager) { tab, position ->
tab.text = tabTitles[position]
tab.setIcon(tabIcons[position])
}.attach()
binding.AHPButton.setOnClickListener {
bottomSheetDialog.show()
}
}
I would really appreciate if someone help me get the original color of the icons im setting.
Also how to change the icon size?
Edit 1: The icon is working fine in imageview, its greyed out in tabsitem for some reason. These icons are svg files. Does that have to do anything with the issue i'm facing? Adding the image for reference. 


You can change text and icon using
tabSelectListener. InonTabSelectedyou will get the selected tab and inonTabUnselectedyou will get unselected tab. You can have 2 list one that have drawables for selected state and one for unselected state.Second approach could be you use by declaring
selectedandunselectedstate in xml file. Lets name this xml ascustom_food_selector.xml.Add the custom tab selector drawable as the icon for tabItem.