Android:导航抽屉项目大小 [英] Android: Navigation drawer item size

查看:57
本文介绍了Android:导航抽屉项目大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有导航抽屉的 Android 应用.抽屉从菜单资源文件中获取其项目.

活动项目上面有一个半透明层,这是默认的东西.我的问题是该层的大小/边距.

我想要这个:

代替这个:

I have an Android app with a navigation drawer in it. The drawer gets its items from a menu resource file.

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

The active item has a semi-transparent layer above it, it's the default stuff. My problem is with the size/margin of that layer.

I would like to have this:

Instead of this: https://i.stack.imgur.com/Zlp9p.png

I can make it square following this answer, but it still has a small margin around it.

How can I achieve it?

解决方案

You can use the itemShapeInset* attributes to fill the entire space:

<com.google.android.material.navigation.NavigationView
 app:itemShapeInsetStart="0dp"
 app:itemShapeInsetEnd="0dp"
 app:itemShapeAppearanceOverlay="@style/ShapeAppearanceOverlay.Nav.Square"

and the itemShapeAppearanceOverlay to have square corners:

<style name="ShapeAppearanceOverlay.Nav.Square" parent="">
    <item name="cornerSize">0dp</item>
</style>

这篇关于Android:导航抽屉项目大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆