You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

切换到Theme.Material3后如何将DrawerLayout圆角改为直角

解决Material3下Navigation Drawer圆角恢复为直角的问题

你将Android项目主题从Theme.MaterialComponents.DayNight.DarkActionBar切换到Theme.Material3.DayNight.NoActionBar后,Navigation Drawer出现圆角是因为Material3默认给侧边抽屉添加了圆角样式,要恢复直角可以通过以下方法:

方法一:在App主题中全局覆盖

在res/values/themes.xml(或styles.xml)的应用主题里,添加自定义的形状外观样式,将圆角半径设为0dp:

<style name="Theme.MyApplication" parent="Theme.Material3.DayNight.NoActionBar">
    <!-- 保留你已有的其他主题属性 -->
    <item name="drawerShapeAppearance">@style/CustomDrawerShape</item>
</style>

<style name="CustomDrawerShape" parent="ShapeAppearance.Material3.LargeComponent">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">0dp</item>
</style>

方法二:单独给NavigationView设置样式

如果只想针对某个页面的Drawer生效,可以直接在布局文件的NavigationView标签中指定形状外观:

<com.google.android.material.navigation.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer"
    <!-- 添加这行属性 -->
    app:shapeAppearance="@style/CustomDrawerShape" />

对应的CustomDrawerShape样式和方法一中的一致,将圆角设为0dp即可。

更精准的设置(仅修改右侧圆角)

因为侧边Drawer是从左侧滑出,只有右侧存在圆角,你也可以单独针对右侧的上下圆角设置为0:

<style name="CustomDrawerShape" parent="ShapeAppearance.Material3.LargeComponent">
    <item name="cornerFamilyTopRight">rounded</item>
    <item name="cornerSizeTopRight">0dp</item>
    <item name="cornerFamilyBottomRight">rounded</item>
    <item name="cornerSizeBottomRight">0dp</item>
</style>

内容的提问来源于stack exchange,提问作者Jim Clermonts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 07:35:36