0

I want to change my tab layout icon size. But my icons selected and unselected.

How can I do this ? How can I change image size ? My aim is :When I change the tab selected and unselected icons will change.

I did it. But Icons size are so small. How can I change this ?

Here is my code :

 private void setupTabIcons() {
        int[] tabIcons = {
                R.drawable.menu_join,
                R.drawable.menu_rate_unselected,
                R.drawable.menu_winner_unselected
        };


        tabLayout.getTabAt(0).setIcon(tabIcons[0]);
        tabLayout.getTabAt(1).setIcon(tabIcons[1]);
        tabLayout.getTabAt(2).setIcon(tabIcons[2]);

    }

And My tabSelectedListener

 tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                JZVideoPlayer.releaseAllVideos();
                switch (tab.getPosition())
                {



                    case 0:

                        tab.setIcon(R.drawable.menu_join);
                        tabLayout.getTabAt(1).setIcon(R.drawable.menu_rate_unselected);
                        tabLayout.getTabAt(2).setIcon(R.drawable.menu_winner_unselected);
                        tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#1F7DD4"));

                    break;

                    case 1:
                        tab.setIcon(R.drawable.menu_rate);
                        tabLayout.getTabAt(2).setIcon(R.drawable.menu_winner_unselected);
                        tabLayout.getTabAt(0).setIcon(R.drawable.menu_join_unselected);
                        tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#8AC349"));
                        break;
                    case 2:
                        tab.setIcon(R.drawable.menu_winners);
                        tabLayout.getTabAt(0).setIcon(R.drawable.menu_join_unselected);
                        tabLayout.getTabAt(1).setIcon(R.drawable.menu_rate_unselected);
                        tabLayout.setSelectedTabIndicatorColor(Color.parseColor("#FFC106"));
                        break;



                }
            }
podgradle
  • 336
  • 1
  • 10
  • 17

1 Answers1

0

take a custom view as below

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"
        android:id="@+id/icon"
        android:layout_gravity="center_horizontal" />
</LinearLayout>

Add the above view to your Tablayout like below

View view1 = getLayoutInflater().inflate(R.layout.customtab, null);
view1.findViewById(R.id.icon).setBackgroundResource(R.drawable.icon);
tabLayout.addTab(tabLayout.newTab().setCustomView(view1));
Sabyasachi
  • 3,499
  • 2
  • 14
  • 21