how to add the icon for swipeable tabs

前端 未结 4 463
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 03:24

I am downloading the code from here i want to dispaly tabs with icon how can posssible please help me.

\"enter

4条回答
  •  悲&欢浪女
    2020-12-01 03:38

    If you are using a TabLayout, just do this (This example uses three tabs):

     //An array containing your icons from the drawable directory
     final int[] ICONS = new int[]{
                R.drawable.icon_1,
                R.drawable.icon_2,
                R.drawable.icon_3
        };
    
        //Get reference to your Tablayout
        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.setupWithViewPager(mViewPager);
    
        tabLayout.getTabAt(0).setIcon(ICONS[0]);
        tabLayout.getTabAt(1).setIcon(ICONS[1]);
        tabLayout.getTabAt(2).setIcon(ICONS[2]);
    

提交回复
热议问题