android – 如何在TabLayout中设置图标大小?

前端之家收集整理的这篇文章主要介绍了android – 如何在TabLayout中设置图标大小?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的代码
  1. private TabLayout tabLayout;
  2. private int[] tabIcons = {
  3. R.mipmap.ic_compass,R.mipmap.ic_place,R.mipmap.ic_passport,R.mipmap.ic_setting
  4. };
  5.  
  6.  
  7. ...
  8. tabLayout.getTabAt(0).setIcon(tabIcons[0]);
  9. tabLayout.getTabAt(1).setIcon(tabIcons[1]);
  10. tabLayout.getTabAt(2).setIcon(tabIcons[2]);
  11. tabLayout.getTabAt(3).setIcon(tabIcons[3]);

图标的大小取决于图像大小.我怎么能调整它?

解决方法

设置图标填充
  1. for (int i = 0; i < tablayout.getTabWidget().getChildCount(); i++)
  2. {
  3. tablayout.getTabWidget().getChildAt(i).setPadding(10,10,10);
  4. }

猜你在找的Android相关文章