Closed denebchorny closed 8 years ago
Hi sir, Sorry for bother you with a trivial question. But, I'm trying to do a VIEWPAGER+ICON_TABS like yours (Custom tab icon 1) where the icons stay in gray whereas the selected one is white.
It doesn´t work for me.
Let me show you my code:
<!-- CUSTOM TAB ICON --> <nebula.cs.technicalsupport.CustomViews.TintableImageView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content" android:layout_height="match_parent" android:background="?attr/selectableItemBackground" android:scaleType="center" app:tint="@color/white" />
app:tint="@color/white" doesn't work because my icons stay in the same color. Example: http://i.imgur.com/NfXbUqx.png
<!-- SMARTTABLAYOUT --> <com.ogaclejapan.smarttablayout.SmartTabLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/viewpagertab" android:background="@color/blue" android:layout_width="match_parent" android:layout_height="@dimen/tab_height" app:stl_distributeEvenly="true" app:stl_dividerColor="@color/transparent" app:stl_dividerThickness="0dp" app:stl_indicatorColor="@color/transparent" app:stl_indicatorThickness="0dp" app:stl_underlineColor="@color/transparent" app:stl_underlineThickness="0dp" /> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/viewpagertab" />
I'm doing this as in your example, whats different about it?.
<!-- JAVA --> public class MenuBaseFragment extends Fragment { private static final String TAG = MenuBaseFragment.class.getSimpleName(); private FragmentStatePagerItemAdapter mAdapter; private FragmentPagerItems.Creator mPages; @Bind(R.id.viewpager) ViewPager mViewPager; @Bind(R.id.viewpagertab) SmartTabLayout mSmartTabLayout; public static MenuBaseFragment newInstance() { MenuBaseFragment fragment = new MenuBaseFragment(); Bundle args = new Bundle(); fragment.setArguments(args); return fragment; } public MenuBaseFragment() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_menu_base, container, false); ButterKnife.bind(this, view); mPages = FragmentPagerItems.with(getActivity()); mPages.add(R.string.notifications, NotificationsFragment.class); mPages.add(R.string.tickets, TicketsListFragment.class); mPages.add(R.string.requests, RequestsListFragment.class); mPages.add(R.string.availability, AvailabilityFragment.class); mPages.add(R.string.settings, SettingsFragment.class); //Loads the pages into adapter mAdapter = new FragmentStatePagerItemAdapter( getChildFragmentManager(), mPages.create()); final LayoutInflater inf = LayoutInflater.from(getContext()); mSmartTabLayout.setCustomTabView(new SmartTabLayout.TabProvider() { @Override public View createTabView(ViewGroup container, int position, PagerAdapter adapter) { TintableImageView icon = (TintableImageView) inf.inflate(R.layout.custom_tab_icon, container, false); switch (position) { case 0: icon.setImageDrawable(ContextCompat.getDrawable(getContext(), R.mipmap.test)); break; case 1: icon.setImageDrawable(ContextCompat.getDrawable(getContext(), R.mipmap.test)); break; case 2: icon.setImageDrawable(ContextCompat.getDrawable(getContext(), R.mipmap.test)); break; case 3: icon.setImageDrawable(ContextCompat.getDrawable(getContext(), R.mipmap.test)); break; case 4: icon.setImageDrawable(ContextCompat.getDrawable(getContext(), R.mipmap.test)); break; case 5: icon.setImageDrawable(ContextCompat.getDrawable(getContext(), R.mipmap.test)); break; default: throw new IllegalStateException("Invalid position: " + position); } return icon; } }); // Setting the viewpager adapter mViewPager.setAdapter(mAdapter); // Attaching the viewpager to the tabs mSmartTabLayout.setViewPager(mViewPager); return view; } }
@denebchorny I am sorry for the late answer. Already solved?
The following I think that it is either.
Thank you for using :)
Hi sir, Sorry for bother you with a trivial question. But, I'm trying to do a VIEWPAGER+ICON_TABS like yours (Custom tab icon 1) where the icons stay in gray whereas the selected one is white.
It doesn´t work for me.
Let me show you my code:
app:tint="@color/white" doesn't work because my icons stay in the same color. Example: http://i.imgur.com/NfXbUqx.png
I'm doing this as in your example, whats different about it?.