- // Add the new WebView page.
- webViewStateAdapter!!.addPage(newTabNumber, newTab, urlString, moveToTab)
+ // Select the new tab if it is the first one. For some odd reason, Android doesn't select the first tab if it is the only one, which causes problems with the new tab position logic above.
+ if (newTabPosition == 0)
+ tabLayout.selectTab(newTab)
+
+ // Scroll to the new tab position if moving to the new tab.
+ if (moveToTab)
+ tabLayout.post { tabLayout.setScrollPosition(newTabPosition, 0F, false, false) }