androidmaterial-components-androiddrawerlayoutandroid-navigationviewmaterial3

How to make rounded corners in DrawerLayout straight when switching to Theme.Material3


I've started the default Android project, "Navigation Drawer Activity".

enter image description here

I've changed the theme to:

<!-- <style name="Theme.MyApplication" parent="Theme.MaterialComponents.DayNight.DarkActionBar">-->
    <style name="Theme.MyApplication" parent="Theme.Material3.DayNight.NoActionBar">

But then the Drawer has rounded corners:

enter image description here

How can I make these corners straight again?


Solution

  • The corner size of the NavigationView is defined by the drawerLayoutCornerSize attribute in the style (default value with M3 theme = 16dp).

    You can use in your layout:

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        app:drawerLayoutCornerSize="0dp"
    

    or you can define a custom style:

    <style name="App.Material3.NavigationView" parent="Widget.Material3.NavigationView">
        <item name="drawerLayoutCornerSize">0dp</item>
    </style>
    

    and then apply it to the NavigationView

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        style="@style/App.Material3.NavigationView"
    

    enter image description here