SmartTabLayout
SmartTabLayout copied to clipboard
Icon tabs not show
hi thanks for nice library.
I'll try to custom tab view with icon and text. But the icon not show. this my code ,,,
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
adapter = new FragmentPagerItemAdapter(getSupportFragmentManager(), FragmentPagerItems.with(this).
add("Request", Fragment1.class).
add("History", Fragment2.class).
add("Message", Fragment3.class).
create());
viewPager.setAdapter(adapter);
viewPagerTab.setViewPager(viewPager);
final LayoutInflater inflater = LayoutInflater.from(this);
final Resources res = getResources();
viewPagerTab.setCustomTabView(new SmartTabLayout.TabProvider() {
@Override
public View createTabView(ViewGroup container, int position, PagerAdapter adapter) {
View itemView = inflater.inflate(R.layout.custom_tab_icon_and_text, container, false);
TextView text = (TextView) itemView.findViewById(R.id.custom_tab_text);
text.setText(adapter.getPageTitle(position));
TintableImageView icon = (TintableImageView) itemView.findViewById(R.id.custom_tab_icon);
switch (position) {
case 0:
icon.setImageDrawable(res.getDrawable(R.drawable.ic_flash_on_white_24dp));
break;
case 1:
icon.setImageDrawable(res.getDrawable(R.drawable.ic_flash_on_white_24dp));
break;
case 2:
icon.setImageDrawable(res.getDrawable(R.drawable.ic_flash_on_white_24dp));
break;
default:
throw new IllegalStateException("Invalid position: " + position);
}
return itemView;
}
});
this my xml custom tab
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/selectableItemBackground"
<android.support.v4.widget.Space android:id="@+id/center_anchor" android:layout_width="0dp" android:layout_height="0dp" android:layout_centerInParent="true" />
<com.package.view.TintableImageView android:id="@+id/custom_tab_icon" android:layout_width="24dp" android:layout_height="24dp" android:layout_above="@id/center_anchor" android:layout_centerHorizontal="true" android:scaleType="center" android:src="@drawable/custom_icon" app:tint="@color/grey_700" /> <TextView android:id="@+id/custom_tab_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/center_anchor" android:layout_centerHorizontal="true" android:layout_marginTop="2dp" android:maxLines="1" android:textColor="@color/grey_700" android:textSize="14sp" /> </RelativeLayout>
how to solve this? thanks before
I also have this issue. Can't figure out how to set icons. Not sure if possible but would be very nice to have a method to quickly change the icons with.
Put setCustomViewTab
before setViewPager
. It worked with me.
Thanx burnix!!!!! :D