Skip to content

Commit

Permalink
[Catalog] Add guidance to use Bottom Navigation Bar on compact screen…
Browse files Browse the repository at this point in the history
…s for Navigation Rail

PiperOrigin-RevId: 651507172
  • Loading branch information
imhappi authored and paulfthomas committed Jul 22, 2024
1 parent 6b263fa commit 5d85d6b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,29 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<com.google.android.material.navigationrail.NavigationRailView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cat_navigation_rail"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="@menu/navigation_rail_animated_menu"
android:fitsSystemWindows="false"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="@+id/cat_navigation_rail_compact_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:visibility="gone"
android:text="@string/cat_navigation_rail_compact_message" />
</LinearLayout>
</LinearLayout>

Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,6 @@

<string name="cat_navigation_rail_fab_content_desc"
description="Content description for a floating action button in the navigation rail.[CHAR_LIMIT=50]">Navigation Rail FAB</string>

<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>
</resources>

0 comments on commit 5d85d6b

Please sign in to comment.