In the below code example I have created a Tab layout, here I have created two methods, first is add text value and second in declare icons.You can see below example code it clearly describes How to add icon with text in tab layout.
// icon declare
private int[]tabIcons={
R.drawable.male,
R.drawable.female
};
// set Icon position
private void setupTabIcons() {
tabLayout.getTabAt(0).setIcon(tabIcons[0]);
tabLayout.getTabAt(1).setIcon(tabIcons[1]);
}
// tab Text declare
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getFragmentManager());
adapter.addFrag(new MaleTab(), "Male");
adapter.addFrag(new FemaleTab(), "Female");
viewPager.setAdapter(adapter);
}
0 Comment(s)