[TabLayout] tabs font is reset to Roboto when attaching new TabLayoutMediator
Description: Similar to #965, except not while switching tabs, but resetting tabs with new data after view creation. Using a StateFlow in the Fragment's ViewModel, which provides data for tabs, when the StateFlow receives a new value, attaching a new TabLayoutMediator causes the tabs to refresh with the Roboto font instead of the app theme's font. When the tabs are loaded for the first time on view creation, the tabs' font comes from the app theme's fontFamily attribute.
Expected behavior: The font should be the same theme font, both on the initial tab load and any subsequent refreshes.
Source code:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
viewLifecycleOwner.lifecycleScope.launch {
viewModel.info.collect { info ->
with(binding) {
tabMediator?.detach()
pager.adapter = InfoAdapter(info)
tabMediator = TabLayoutMediator(tabs, pager, InfoTabConfigurationStrategy(info)).apply {
attach()
}
}
}
}
}
Minimal sample app repro: Run the app and wait 10 seconds for the tab data refresh. My Application.zip
Android API version: Android 13 (API 33)
Material Library version: 1.6.1 (also 1.7.0-beta01)
Device: Pixel 6 Pro