diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerContainerFragment.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerContainerFragment.java index c868d27f..220e23fe 100644 --- a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerContainerFragment.java +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerContainerFragment.java @@ -13,6 +13,7 @@ import android.widget.Toast; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.tabs.TabLayout; +import com.google.android.material.tabs.TabLayoutMediator; import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputLayout; @@ -102,6 +103,10 @@ public class ViewerContainerFragment extends Fragment { ViewerViewPagerAdapter viewerViewPagerAdapter = new ViewerViewPagerAdapter(requireActivity()); viewPager.setAdapter(viewerViewPagerAdapter); + // Init tab layout + TabLayout tabLayout = view.findViewById(R.id.tab_layout); + new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> tab.setText(viewerViewPagerAdapter.getTabTitle(position))).attach(); + // Init toolbar Toolbar toolbar = view.findViewById(R.id.toolbar); initToolbar(toolbar, true, documentName); @@ -119,7 +124,6 @@ public class ViewerContainerFragment extends Fragment { }); } else { logger.debug("ViewerContainerFragment", "hasCombined: " + hasCombined); - TabLayout tabLayout = view.findViewById(R.id.tab_layout); tabLayout.setVisibility(View.GONE); viewerViewPagerAdapter.addFragment(ViewerBodyFragment.newInstance(documentId, documentName), documentName); } diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerViewPagerAdapter.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerViewPagerAdapter.java index cdf742b0..e3f998fe 100644 --- a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerViewPagerAdapter.java +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerViewPagerAdapter.java @@ -1,6 +1,7 @@ package one.nem.lacerta.component.viewer; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; @@ -35,4 +36,9 @@ public class ViewerViewPagerAdapter extends FragmentStateAdapter { public int getItemCount() { return fragmentArrayList == null ? 0 : fragmentArrayList.size(); } + + @Nullable + public CharSequence getTabTitle(int position) { + return fragmentTitleList.get(position); + } }