Setting icons when a tab is selected
You check whether the index of the tab equals the position. If this is the case, use the selected icon, otherwise use the unselected one:

for(int i = 0; i &lt; 5; i++) {  // maybe replace 5 with a constant declaration...
    if(i == position)
        tabLayout.getTabAt(i).setIcon(tabSelected[i]);
    else
        tabLayout.getTabAt(i).setIcon(tabsUnselected[i]);
}