+ override fun onConfigurationChanged(newConfig: Configuration) {
+ // Run the default commands.
+ super.onConfigurationChanged(newConfig)
+
+ // Get the current page.
+ val currentPage = webViewViewPager2.currentItem
+
+ // Toggle the pages if there is more than one so that the view pager will recalculate their size.
+ if (currentPage > 0) {
+ // Switch to the previous page after 25 milliseconds.
+ webViewViewPager2.postDelayed ({ webViewViewPager2.currentItem = (currentPage - 1) }, 25)
+
+ // Switch back to the current page after the view pager has quiesced (which we are deciding should be 25 milliseconds).
+ webViewViewPager2.postDelayed ({ webViewViewPager2.currentItem = currentPage }, 25)
+ }
+
+ // Scroll to the current tab position after 25 milliseconds.
+ tabLayout.postDelayed ({ tabLayout.setScrollPosition(currentPage, 0F, false, false) }, 25)
+ }
+