Skip to content

Commit 5d85d6b

Browse files
imhappipaulfthomas
authored andcommitted
[Catalog] Add guidance to use Bottom Navigation Bar on compact screens for Navigation Rail
PiperOrigin-RevId: 651507172
1 parent 6b263fa commit 5d85d6b

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

catalog/java/io/material/catalog/navigationrail/NavigationRailAnimatedDemoFragment.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import io.material.catalog.R;
2020

21+
import android.annotation.SuppressLint;
22+
import android.content.pm.ActivityInfo;
23+
import android.content.res.Configuration;
2124
import android.os.Bundle;
2225
import android.view.LayoutInflater;
2326
import android.view.View;
@@ -31,10 +34,20 @@
3134
*/
3235
public class NavigationRailAnimatedDemoFragment extends DemoFragment {
3336

37+
@SuppressLint("SourceLockedOrientationActivity")
3438
@Override
3539
public View onCreateDemoView(
3640
LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
37-
return layoutInflater.inflate(
41+
View v = layoutInflater.inflate(
3842
R.layout.cat_navigation_rail_animated, viewGroup, false /* attachToRoot */);
43+
Configuration config = getResources().getConfiguration();
44+
View compactMessage = v.findViewById(R.id.cat_navigation_rail_compact_msg);
45+
if (config.smallestScreenWidthDp <= 600) { // 600dp and below is classified as compact
46+
compactMessage.setVisibility(View.VISIBLE);
47+
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
48+
} else {
49+
getActivity().setRequestedOrientation(config.orientation);
50+
}
51+
return v;
3952
}
4053
}

catalog/java/io/material/catalog/navigationrail/res/layout/cat_navigation_rail_animated.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,29 @@
1414
~ See the License for the specific language governing permissions and
1515
~ limitations under the License.
1616
-->
17+
<LinearLayout
18+
android:layout_width="match_parent"
19+
android:layout_height="match_parent"
20+
android:orientation="horizontal"
21+
xmlns:android="http://schemas.android.com/apk/res/android">
1722
<com.google.android.material.navigationrail.NavigationRailView
18-
xmlns:android="http://schemas.android.com/apk/res/android"
1923
xmlns:app="http://schemas.android.com/apk/res-auto"
2024
android:id="@+id/cat_navigation_rail"
2125
android:layout_width="wrap_content"
2226
android:layout_height="match_parent"
2327
app:menu="@menu/navigation_rail_animated_menu"
2428
android:fitsSystemWindows="false"/>
29+
<LinearLayout
30+
android:layout_width="0dp"
31+
android:layout_height="match_parent"
32+
android:layout_weight="1">
33+
<TextView
34+
android:id="@+id/cat_navigation_rail_compact_msg"
35+
android:layout_width="wrap_content"
36+
android:layout_height="wrap_content"
37+
android:gravity="center"
38+
android:visibility="gone"
39+
android:text="@string/cat_navigation_rail_compact_message" />
40+
</LinearLayout>
41+
</LinearLayout>
2542

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,6 @@
103103

104104
<string name="cat_navigation_rail_fab_content_desc"
105105
description="Content description for a floating action button in the navigation rail.[CHAR_LIMIT=50]">Navigation Rail FAB</string>
106+
107+
<string name="cat_navigation_rail_compact_message" description="Usage guidance for Navigation Rail advising using a Bottom Navigation Bar on compact screens instead. [CHAR_LIMIT=50]">This demo is for demonstration purposes only. Use a Bottom Navigation Bar instead on compact screen sizes.</string>
106108
</resources>

0 commit comments

Comments
 (0)