2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TabLayoutでアイコンが設定できない問題

Last updated at Posted at 2018-01-28

TabLayoutとViewPagerで、アプリを作ろうとしていました

###困っていたこと

tabLayout.getTabAt(0).setIcon(R.drawable.ic_tab0);

何故かこのコードでアイコンが設定できませんでした

###解決法
問題点: コードの順番
ViewPagerをセットした後でアイコンをセットするようです

###コード

TabLayout tabLayout = (TabLayout)findViewById(R.id.tabLayout);
// set viewPager to TabLayout
tabLayout.setupWithViewPager(viewPager);
// set icons to TabLayout
tabLayout.getTabAt(0).setIcon(R.drawable.ic_input);
tabLayout.getTabAt(1).setIcon(R.drawable.ic_hospital);
tabLayout.getTabAt(2).setIcon(R.drawable.ic_log);

###参考
https://stackoverflow.com/questions/30892545/tablayout-with-icons-only

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?