From 5d85d6bd6fd66cbd87545827d3f5dea3a97bf778 Mon Sep 17 00:00:00 2001 From: rightnao Date: Thu, 11 Jul 2024 19:59:04 +0000 Subject: [PATCH] [Catalog] Add guidance to use Bottom Navigation Bar on compact screens for Navigation Rail PiperOrigin-RevId: 651507172 --- .../NavigationRailAnimatedDemoFragment.java | 15 ++++++++++++++- .../layout/cat_navigation_rail_animated.xml | 19 ++++++++++++++++++- .../navigationrail/res/values/strings.xml | 2 ++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/catalog/java/io/material/catalog/navigationrail/NavigationRailAnimatedDemoFragment.java b/catalog/java/io/material/catalog/navigationrail/NavigationRailAnimatedDemoFragment.java index 69775c18dc0..542d32290f1 100644 --- a/catalog/java/io/material/catalog/navigationrail/NavigationRailAnimatedDemoFragment.java +++ b/catalog/java/io/material/catalog/navigationrail/NavigationRailAnimatedDemoFragment.java @@ -18,6 +18,9 @@ import io.material.catalog.R; +import android.annotation.SuppressLint; +import android.content.pm.ActivityInfo; +import android.content.res.Configuration; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -31,10 +34,20 @@ */ public class NavigationRailAnimatedDemoFragment extends DemoFragment { + @SuppressLint("SourceLockedOrientationActivity") @Override public View onCreateDemoView( LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) { - return layoutInflater.inflate( + View v = layoutInflater.inflate( R.layout.cat_navigation_rail_animated, viewGroup, false /* attachToRoot */); + Configuration config = getResources().getConfiguration(); + View compactMessage = v.findViewById(R.id.cat_navigation_rail_compact_msg); + if (config.smallestScreenWidthDp <= 600) { // 600dp and below is classified as compact + compactMessage.setVisibility(View.VISIBLE); + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } else { + getActivity().setRequestedOrientation(config.orientation); + } + return v; } } diff --git a/catalog/java/io/material/catalog/navigationrail/res/layout/cat_navigation_rail_animated.xml b/catalog/java/io/material/catalog/navigationrail/res/layout/cat_navigation_rail_animated.xml index 43dcdc26d69..eeda829a7d8 100644 --- a/catalog/java/io/material/catalog/navigationrail/res/layout/cat_navigation_rail_animated.xml +++ b/catalog/java/io/material/catalog/navigationrail/res/layout/cat_navigation_rail_animated.xml @@ -14,12 +14,29 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> + + + + + diff --git a/catalog/java/io/material/catalog/navigationrail/res/values/strings.xml b/catalog/java/io/material/catalog/navigationrail/res/values/strings.xml index 8560cd27882..bbaefe7c1ac 100644 --- a/catalog/java/io/material/catalog/navigationrail/res/values/strings.xml +++ b/catalog/java/io/material/catalog/navigationrail/res/values/strings.xml @@ -103,4 +103,6 @@ Navigation Rail FAB + + This demo is for demonstration purposes only. Use a Bottom Navigation Bar instead on compact screen sizes.