ogaclejapan / SmartTabLayout

A custom ViewPager title strip which gives continuous feedback to the user when scrolling
Apache License 2.0
7.09k stars 1.34k forks source link

Set Tab Icon on the basis of tab name #273

Closed sebinpaul closed 5 years ago

sebinpaul commented 5 years ago

First of all thank you for such a great library!

The normal icon tabs are implemented this way-

layout.setCustomTabView(new SmartTabLayout.TabProvider() { @Override public View createTabView(ViewGroup container, int position, PagerAdapter adapter) { ImageView icon = (ImageView) inflater.inflate(R.layout.custom_tab_icon1, container, false); switch (position) { case 0: icon.setImageDrawable(res.getDrawable(R.drawable.ic_home_white_24dp)); break; case 1: icon.setImageDrawable(res.getDrawable(R.drawable.ic_search_white_24dp)); break; case 2: icon.setImageDrawable(res.getDrawable(R.drawable.ic_person_white_24dp)); break; case 3: icon.setImageDrawable(res.getDrawable(R.drawable.ic_flash_on_white_24dp)); break; default: throw new IllegalStateException("Invalid position: " + position); } return icon; } });

In this code snippet icons are set on the basis of position. Is there any way I can set it on the basis of tab title?(instead of position, tab title could be used) Actually in my I give the users the ability to reorder/disable tabs.

Is there any way I can achieve this?