Skip to content

Commit 17855c1

Browse files
hunterstichpaulfthomas
authored andcommitted
[TopAppBar] Fixed compress effect when toolbar is set as a support action bar and hiddin/shown.
getSupportActionBar.show/hide uses visibility to show/hide the toolbar which conflicted with the compress effect's use of Visibility to remove the toolbar when completely masked. This updates the compress effect to use alpha instead of visibility. PiperOrigin-RevId: 619253990
1 parent a2d9bac commit 17855c1

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

catalog/java/io/material/catalog/topappbar/TopAppBarCompressEffectFragment.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ public View onCreateDemoView(
6868
showHideTabsButton.setOnCheckedChangeListener(
6969
(buttonView, isChecked) -> updateTabVisibility(tabs, isChecked));
7070

71+
ToggleButton showHideToolbarButton = view.findViewById(R.id.show_hide_toolbar_button);
72+
showHideToolbarButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
73+
if (isChecked) {
74+
activity.getSupportActionBar().show();
75+
} else {
76+
activity.getSupportActionBar().hide();
77+
}
78+
});
79+
7180
return view;
7281
}
7382

catalog/java/io/material/catalog/topappbar/res/layout/cat_topappbar_compress_effect_fragment.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@
108108
android:textOn="@string/cat_topappbar_compress_hide_tabs_toggle_label"
109109
android:textOff="@string/cat_topappbar_compress_show_tabs_toggle_label" />
110110

111+
<ToggleButton
112+
android:id="@+id/show_hide_toolbar_button"
113+
android:layout_width="wrap_content"
114+
android:layout_height="wrap_content"
115+
android:layout_gravity="center_horizontal"
116+
android:layout_margin="8dp"
117+
android:checked="true"
118+
android:textOn="@string/cat_topappbar_compress_hide_toolbar_toggle_label"
119+
android:textOff="@string/cat_topappbar_compress_show_toolbar_toggle_label" />
120+
111121
<TextView
112122
android:layout_width="wrap_content"
113123
android:layout_height="wrap_content"

catalog/java/io/material/catalog/topappbar/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
<string name="cat_topappbar_compress_toolbar_title">Compress Title</string>
107107
<string name="cat_topappbar_compress_show_tabs_toggle_label">Show tabs</string>
108108
<string name="cat_topappbar_compress_hide_tabs_toggle_label">Hide tabs</string>
109+
<string name="cat_topappbar_compress_show_toolbar_toggle_label">Show toolbar</string>
110+
<string name="cat_topappbar_compress_hide_toolbar_toggle_label">Hide toolbar</string>
109111

110112
<string name="cat_topappbar_tabs_label_all">All</string>
111113
<string name="cat_topappbar_tabs_label_shopping">Shopping</string>

lib/java/com/google/android/material/appbar/AppBarLayout.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,16 +2579,16 @@ public void onOffsetChanged(
25792579
// invisible. Otherwise, on API <= 24 a ghost rect that is outside of the drawing rect will
25802580
// be ignored and the child would be drawn with no clipping.
25812581
if (offsetY >= ghostRect.height()) {
2582-
child.setVisibility(INVISIBLE);
2582+
child.setAlpha(0f);
25832583
} else {
2584-
child.setVisibility(VISIBLE);
2584+
child.setAlpha(1f);
25852585
}
25862586
ViewCompat.setClipBounds(child, ghostRect);
25872587
} else {
25882588
// Reset both the clip bounds and translationY of this view
25892589
ViewCompat.setClipBounds(child, null);
25902590
child.setTranslationY(0);
2591-
child.setVisibility(VISIBLE);
2591+
child.setAlpha(1f);
25922592
}
25932593
}
25942594
}

0 commit comments

Comments
 (0)