简体   繁体   English

切换到 Theme.Material3 时如何在 DrawerLayout 中直接制作圆角

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

I've started the default Android project, "Navigation Drawer Activity".我已经启动了默认的 Android 项目“Navigation Drawer Activity”。

在此处输入图像描述

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:但是抽屉有圆角:

在此处输入图像描述

How can I make these corners straight again?我怎样才能使这些角再次变直?

The corner size of the NavigationView is defined by the drawerLayoutCornerSize attribute in the style (default value with M3 theme = 16dp ). NavigationView的角尺寸由样式中的drawerLayoutCornerSize属性定义( M3主题的默认值 = 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然后将它应用到NavigationView

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

在此处输入图像描述

Just add this line in the com.google.android.material.navigation.NavigationView只需在com.google.android.material.navigation.NavigationView添加这一行

app:drawerLayoutCornerSize="0dp"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM