com.google.android.material.tabs.TabLayoutMediator Java Examples
The following examples show how to use
com.google.android.material.tabs.TabLayoutMediator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactWithAnyEmojiBottomSheetDialogFragment.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (savedInstanceState == null) { FrameLayout container = requireDialog().findViewById(R.id.container); LayoutInflater layoutInflater = LayoutInflater.from(requireContext()); View statusBarShader = layoutInflater.inflate(R.layout.react_with_any_emoji_status_fade, container, false); TabLayout categoryTabs = (TabLayout) layoutInflater.inflate(R.layout.react_with_any_emoji_tabs, container, false); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewUtil.getStatusBarHeight(container)); statusBarShader.setLayoutParams(params); container.addView(statusBarShader, 0); container.addView(categoryTabs); ViewCompat.setOnApplyWindowInsetsListener(container, (v, insets) -> insets.consumeSystemWindowInsets()); new TabLayoutMediator(categoryTabs, categoryPager, (tab, position) -> { tab.setCustomView(react_with_any_emoji_tab) .setIcon(ThemeUtil.getThemedDrawable(requireContext(), viewModel.getCategoryIconAttr(position))); }).attach(); } }
Example #2
Source File: DynamicViewPager2Fragment.java From dynamic-support with Apache License 2.0 | 6 votes |
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (getActivity() == null) { return; } ((DynamicActivity) requireActivity()).addHeader(R.layout.ads_tabs, true); mTabLayout = requireActivity().findViewById(R.id.ads_tab_layout); mViewPager.setOffscreenPageLimit(getItemCount()); mViewPager.setAdapter(new ViewPagerAdapter(this, this)); new TabLayoutMediator(mTabLayout, mViewPager, new TabLayoutMediator.TabConfigurationStrategy() { @Override public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) { tab.setText(getTitle(position)); } }).attach(); if (getArguments() != null && requireArguments().containsKey(ADS_ARGS_VIEW_PAGER_PAGE)) { setPage(requireArguments().getInt(ADS_ARGS_VIEW_PAGER_PAGE)); } }
Example #3
Source File: TeiDashboardMobileActivity.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void tabLayoutMediator(ViewPager2 viewPager) { new TabLayoutMediator(binding.tabLayout, viewPager, (tab, position) -> { if (OrientationUtilsKt.isLandscape()) { setupTabletTabTitles(tab, position); } else { setupTabTitles(tab, position); } }).attach(); }
Example #4
Source File: ViewPagerFragment.java From AndroidNavigation with MIT License | 5 votes |
private void initView(View view) { toolbar = view.findViewById(R.id.toolbar); AppBarLayout appBarLayout = view.findViewById(R.id.appbar_layout); // important if (isStatusBarTranslucent()) { appendStatusBarPadding(appBarLayout); } TabLayout tabLayout = view.findViewById(R.id.tab_layout); ViewPager2 viewPager = view.findViewById(R.id.view_pager); tabLayout.addTab(tabLayout.newTab().setText("Android")); tabLayout.addTab(tabLayout.newTab().setText("Awesome")); tabLayout.addTab(tabLayout.newTab().setText("Navigation")); viewPager.setAdapter(new ViewPagerAdapter(this)); new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> { String[] titles = new String[]{"Android", "Awesome", "Navigation"}; tab.setText(titles[position]); viewPager.setCurrentItem(position); }).attach(); viewPager.setCurrentItem(0); }
Example #5
Source File: ChannelFragment.java From lbry-android with MIT License | 4 votes |
private void renderClaim() { if (claim == null) { renderNothingAtLocation(); return; } loadSubCount(); checkIsFollowing(); layoutLoadingState.setVisibility(View.GONE); layoutDisplayArea.setVisibility(View.VISIBLE); String thumbnailUrl = claim.getThumbnailUrl(); String coverUrl = claim.getCoverUrl(); textTitle.setText(Helper.isNullOrEmpty(claim.getTitle()) ? claim.getName() : claim.getTitle()); Context context = getContext(); if (context != null && !Helper.isNullOrEmpty(coverUrl)) { Glide.with(context.getApplicationContext()).load(coverUrl).centerCrop().into(imageCover); } if (context != null && !Helper.isNullOrEmpty(thumbnailUrl)) { Glide.with(context.getApplicationContext()).load(thumbnailUrl).apply(RequestOptions.circleCropTransform()).into(imageThumbnail); noThumbnailView.setVisibility(View.GONE); } else { imageThumbnail.setVisibility(View.GONE); int bgColor = Helper.generateRandomColorForValue(claim.getClaimId()); Helper.setIconViewBackgroundColor(noThumbnailView, bgColor, false, getContext()); noThumbnailView.setVisibility(View.VISIBLE); if (claim.getName() != null) { textAlpha.setText(claim.getName().substring(1, 2)); } } try { if (tabPager.getAdapter() == null && context instanceof MainActivity) { tabPager.setAdapter(new ChannelPagerAdapter(claim, (MainActivity) context)); } new TabLayoutMediator(tabLayout, tabPager, new TabLayoutMediator.TabConfigurationStrategy() { @Override public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) { switch (position) { case 0: tab.setText(R.string.content); break; case 1: tab.setText(R.string.about); break; case 2: tab.setText(R.string.comments); break; } } }).attach(); } catch (IllegalStateException ex) { // TODO: Fix why this is happening // pass } }