{"id":1798,"date":"2021-08-19T12:19:17","date_gmt":"2021-08-19T19:19:17","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/surface-duo\/?p=1798"},"modified":"2021-08-19T12:19:17","modified_gmt":"2021-08-19T19:19:17","slug":"dual-screen-navigation-rail","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/surface-duo\/dual-screen-navigation-rail\/","title":{"rendered":"Dual-screen Navigation Rail"},"content":{"rendered":"<p>\n  Hello Android developers!\n<\/p>\n<p>\n  Google recently published a <a href=\"https:\/\/developer.android.com\/large-screens\">new landing page<\/a> for building responsive layouts for larger screens (including dual-screen and foldable devices). The new NavigationRail widget includes features and guidance as an efficient way to navigate app features on larger screens.\n<\/p>\n<h2>About NavigationRail<\/h2>\n<p><a href=\"https:\/\/material.io\/components\/navigation-rail\">NavigationRail<\/a> is a material design component for top-level navigation on larger screens. It provides a variety of display options with icons, text, and even a floating action button if needed. For a responsive experience across phones, dual-screen\/foldable, and tablet devices, it can be coupled with bottom navigation on smaller\/narrower screens.\n<\/p>\n<h2>NavigationRail on dual-screens<\/h2>\n<p>\n  In this dual-screen <a href=\"https:\/\/github.com\/CesarValiente\/NavigationRail-WM-Sample\">NavigationRail sample<\/a>, the app adapts to one or two screens and uses bottom navigation on the single screen but deploys the NavigationRail layout when spanned across the entire display, creating a vertical navigation bar.\n<\/p>\n<p>\n  The layout XML for the two controls appears in the activity_main.xml:\n<\/p>\n<pre>&lt;com.google.android.material.navigationrail.NavigationRailView\r\n    android:id=\"@+id\/navigation_rail\"\r\n    android:layout_width=\"wrap_content\"\r\n    android:layout_height=\"match_parent\"\r\n    android:visibility=\"gone\"\r\n    app:layout_constraintLeft_toLeftOf=\"parent\"\r\n    app:layout_constraintTop_toTopOf=\"parent\"\r\n    app:menu=\"@menu\/nav_menu\" \/&gt;\r\n&lt;com.google.android.material.bottomnavigation.BottomNavigationView\r\n    android:id=\"@+id\/bottom_nav_view\"\r\n    android:layout_width=\"0dp\"\r\n    android:layout_height=\"wrap_content\"\r\n    android:layout_marginStart=\"0dp\"\r\n    android:layout_marginEnd=\"0dp\"\r\n    android:background=\"?android:attr\/windowBackground\"\r\n    android:visibility=\"gone\"\r\n    app:layout_constraintBottom_toBottomOf=\"parent\"\r\n    app:layout_constraintLeft_toLeftOf=\"parent\"\r\n    app:layout_constraintRight_toRightOf=\"parent\"\r\n    app:menu=\"@menu\/nav_menu\" \/&gt;<\/pre>\n<p>\n  The correct widget is shown based on the presence of a display feature. But how do we know if there is a display feature (hinge or fold) on the device? To detect device display features when using an app, you can use <a href=\"https:\/\/developer.android.com\/jetpack\/androidx\/releases\/window\">Jetpack Window Manager<\/a>. View  <a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/jetpack-window-manager-alpha10\/\">last week\u2019s blog post on Jetpack Window Manager<\/a> to learn more about using this component.\n<\/p>\n<p>\n  Once the app detects if there is a display feature or not, the app will show the correct component and hide the other:\n<\/p>\n<pre>bottomNavView.visibility = View.GONE\r\nnavRailView.visibility = View.VISIBLE<\/pre>\n<p>\n  As you can see, it\u2019s easy to switch from one component to the other using their visibility parameters, but there are some additional alternatives you could consider. For example, we could inflate the specific layout that contains the correct component dynamically in code. If you want to see how that\u2019s done, we created a <a href=\"https:\/\/github.com\/CesarValiente\/NavigationRail-WM-Sample\/tree\/replacing_layouts\">separated branch following that approach<\/a>.\n<\/p>\n<p>\n  Once you run the sample you will see how when the app is running on single-screen mode it shows a BottomNavigation and when the app is spanned across two displays, it shows a NavigationRail:\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"1632\" height=\"1278\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/graphical-user-interface-application-description.png\" class=\"wp-image-1799\" alt=\"Bottom navigation is used on smaller screen area\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/graphical-user-interface-application-description.png 1632w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/graphical-user-interface-application-description-300x235.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/graphical-user-interface-application-description-1024x802.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/graphical-user-interface-application-description-768x601.png 768w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/graphical-user-interface-application-description-1536x1203.png 1536w\" sizes=\"(max-width: 1632px) 100vw, 1632px\" \/><br \/><em>Figure 1: on smaller screens, use BottomNavigation<\/em>\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"1160\" height=\"908\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/graphical-user-interface-application-description-1.png\" class=\"wp-image-1800\" alt=\"Navigation rail is used on larger screen area\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/graphical-user-interface-application-description-1.png 1160w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/graphical-user-interface-application-description-1-300x235.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/graphical-user-interface-application-description-1-1024x802.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/graphical-user-interface-application-description-1-768x601.png 768w\" sizes=\"(max-width: 1160px) 100vw, 1160px\" \/><br \/><em>Figure 2: on larger screens, use NavigationRail<\/em>\n<\/p>\n<h2>NavigationRail on foldables<\/h2>\n<p>\n  On other large-screen devices, including foldable devices, we can also switch between the NavigationRail and BottomNavigation. NavigationRail works best when the app is using the entire screen, but the BottomNavigation is used when the app is smaller due to multi-windowing:\n<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/image3-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/image3-1.png\" alt=\"Foldable device with navigation rail\" width=\"762\" height=\"943\" class=\"alignnone size-full wp-image-1804\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/image3-1.png 762w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/image3-1-242x300.png 242w\" sizes=\"(max-width: 762px) 100vw, 762px\" \/><\/a><em>Figure 3: Full screen app on a foldable device<\/em>\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"720\" height=\"893\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/word-image-1.png\" class=\"wp-image-1801\" alt=\"Foldable device with multi-windowing and a small app with navigation rail\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/word-image-1.png 720w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2021\/08\/word-image-1-242x300.png 242w\" sizes=\"(max-width: 720px) 100vw, 720px\" \/><em>Figure 4: BottomNavigation is used for smaller screen area<\/em>\n<\/p>\n<h2>Flutter too<\/h2>\n<p>\n  There is also a <a href=\"https:\/\/api.flutter.dev\/flutter\/material\/NavigationRail-class.html\">Flutter version of NavigationRail<\/a> component, which provides the same user experience across all the supported Flutter platforms. It should be paired with <a href=\"https:\/\/api.flutter.dev\/flutter\/material\/BottomNavigationBar-class.html\">BottmNavigationBar<\/a> for smaller screens, just as with the Android native widget.\n<\/p>\n<h2>Resources and feedback<\/h2>\n<p>\n  Check out the\u00a0Microsoft <a href=\"https:\/\/docs.microsoft.com\/dual-screen\/\">Surface Duo developer documentation<\/a>\u00a0and\u00a0<a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/\">past\u00a0blog posts<\/a>\u00a0for links and details on all our samples. You can find\u00a0our\u00a0<a href=\"https:\/\/github.com\/microsoft\/surface-duo-sdk-samples\">samples<\/a>\u00a0on GitHub.\u00a0\n<\/p>\n<p>\n  If you have any questions, or would like to tell us about your apps, use the\u00a0<a href=\"http:\/\/aka.ms\/SurfaceDuoSDK-Feedback\">feedback forum<\/a>\u00a0or message us on Twitter\u00a0<a href=\"https:\/\/twitter.com\/surfaceduodev\">@surfaceduodev<\/a>.\u00a0\n<\/p>\n<p>\n  Finally, please join us for our <a href=\"https:\/\/twitch.tv\/surfaceduodev\">dual screen developer livestream<\/a> at 11am (Pacific time) each Friday \u2013 mark it in your calendar and check out the <a href=\"https:\/\/www.youtube.com\/channel\/UClGu9QLtPNz8OdddBfhZXPA\">archives on YouTube<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Android developers! Google recently published a new landing page for building responsive layouts for larger screens (including dual-screen and foldable devices). The new NavigationRail widget includes features and guidance as an efficient way to navigate app features on larger screens. About NavigationRail NavigationRail is a material design component for top-level navigation on larger screens. [&hellip;]<\/p>\n","protected":false},"author":30297,"featured_media":1800,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[31,706,473],"class_list":["post-1798","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-surface-duo-sdk","tag-dual-screen-development","tag-jetpack-window-manager","tag-kotlin"],"acf":[],"blog_post_summary":"<p>Hello Android developers! Google recently published a new landing page for building responsive layouts for larger screens (including dual-screen and foldable devices). The new NavigationRail widget includes features and guidance as an efficient way to navigate app features on larger screens. About NavigationRail NavigationRail is a material design component for top-level navigation on larger screens. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/1798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/users\/30297"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/comments?post=1798"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/1798\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media\/1800"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media?parent=1798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/categories?post=1798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/tags?post=1798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}