From a84bd906dcf3365fe52a10e67ca693003426b4c7 Mon Sep 17 00:00:00 2001 From: rightnao Date: Fri, 24 Feb 2023 15:10:06 +0000 Subject: [PATCH] [TabLayout] Fix issue with indicator not being drawn when viewpager starts scrolling before onLayout is called PiperOrigin-RevId: 512062664 (cherry picked from commit 34d6a14700a348a9c3f50d4c34c201f21b6b3310) --- lib/java/com/google/android/material/tabs/TabLayout.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/java/com/google/android/material/tabs/TabLayout.java b/lib/java/com/google/android/material/tabs/TabLayout.java index b9f24b3856d..252c0c089dc 100644 --- a/lib/java/com/google/android/material/tabs/TabLayout.java +++ b/lib/java/com/google/android/material/tabs/TabLayout.java @@ -3316,8 +3316,11 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { * in a viewpager. */ private void jumpIndicatorToPosition(int position) { - // Don't update the indicator position if the scroll state is not idle. - if (viewPagerScrollState != SCROLL_STATE_IDLE) { + // Don't update the indicator position if the scroll state is not idle, and the indicator + // is drawn. + if (viewPagerScrollState != SCROLL_STATE_IDLE + && !(getTabSelectedIndicator().getBounds().left == -1 + && getTabSelectedIndicator().getBounds().right == -1)) { return; } final View currentView = getChildAt(position);