How to increase icon size of tabs in TabLayout

后端 未结 6 901
刺人心
刺人心 2020-12-05 00:43

I am trying to increase icon size of tabs in my app. Icon sizes are fixed tried out many ways but nothing is working, finally tried the following but no change in size.Pleas

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 01:19

    This is a custom TabLayout it can help a lot!

    public class TabView extends TabLayout {
    
    public TabView(Context context) {
        super(context);
        init();
    }
    
    public TabView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    
    public TabView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }
    
    private void init() {
        int padding = 10;
    
        int[] icons = new int[]{R.drawable.ic_tel, R.drawable.ic_speaker, R.drawable.ic_camera, R.drawable.ic_home};
    
        for (int i = 0; i < icons.length; i++) {
            ImageView imageView = new ImageView(getContext());
            imageView.setBackgroundColor(Color.TRANSPARENT);
            imageView.setImageResource(icons[i]);
            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            imageView.setPadding(padding, padding, padding, padding);
            if (i==3){
                addTab(newTab().setCustomView(imageView), i , true);
            } else {
                addTab(newTab().setCustomView(imageView), i);
            }
        }
    
    }
    

    }

提交回复
热议问题