2016-08-25 23 views
0

我使用viewpager和Tablayout來實現選項卡片段,然後在選項卡上使用setIcon,但圖標太小。我每天都在尋找解決方案。安裝樣式 自定義選項卡等...我嘗試構建自定義選項卡,但它總是崩潰。任何想法?如何更改TabLayout中的圖標大小

這裏是我的代碼

 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); 

回答

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 

       } 
      } 
     } 
    } 
+0

我現在想它 –

+0

哪一部分改變圖標的​​大小? –

+0

您將imageview設置爲viewChild,然後您可以通過編程方式更改圖標大小 – kgandroid