如何更改TabLayout中的图标大小

时间:2016-08-25 10:16:41

标签: android

我使用viewpager和Tablayout实现制表符片段然后我在选项卡上设置了setIcon,但图标太小了。我每天都在寻找解决方案。设置风格 自定义选项卡等...我尝试构建自定义选项卡但它总是分解。任何的想法?

这是我的代码

     viewPager= (ViewPager)findViewById(R.id.viewPager);
    viewPager.setAdapter(newCustomAdapter(getSupportFragmentManager(),getApplicationContext()));
    tabLayout=(TabLayout)findViewById(R.id.tabLayout);


   Toolbar mytoolbar= (Toolbar)findViewById(R.id.my_toolbar);
    mytoolbar.setTitleTextColor(Color.WHITE);
    setSupportActionBar(mytoolbar);

    getSupportActionBar().setTitle(R.string.mytitle);

    tabLayout.setupWithViewPager(viewPager);
    tabLayout.getTabAt(0).setIcon(R.drawable.ic);
    tabLayout.getTabAt(1).setIcon(R.drawable.taichung);
    tabLayout.getTabAt(2).setIcon(R.drawable.ic);

1 个答案:

答案 0 :(得分:0)

试试这个:

protected void changeTabs(TabLayout tabLayout) {
        Logger.print("In change tab font");
        ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
        int tabsCount = vg.getChildCount();
        Logger.print("Tab count--->"+tabsCount);
        for (int j = 0; j < tabsCount; j++) {
            ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
            int tabChildsCount = vgTab.getChildCount();
            for (int i = 0; i < tabChildsCount; i++) {
                View tabViewChild = vgTab.getChildAt(i);
                if (tabViewChild instanceof AppCompatTextView) {
                    ImageView viewChild = (ImageView) tabViewChild;
                    //Now do whatever you want with viewChild

                }
            }
        }
    }