android导航栏所选项目背景大小wrap_content

问题描述

我有一个带有自定义选定项目背景的导航抽屉。这是我背景的xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:right="16dp"
        android:left="16dp">
        <shape android:shape="rectangle">
            <solid android:color="#665EFF" />
            <corners
                android:bottomrighTradius="12dp"
                android:topRighTradius="12dp"
                />
        </shape>
    </item>
</layer-list>

和选择器

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@drawable/background_round_padding"
        android:state_checked="true"
        />
</selector>

我在导航抽屉xml中使用这种样式

    <style name="Widget.Custom.NavigationView" parent="Widget.Design.NavigationView">
    <item name="itemIconTint">@android:color/white</item>
    <item name="itemTextColor">@android:color/white</item>
    <item name="itemBackground">@drawable/drawer_selectedbackground_drawable</item>
</style>

但是背景填充了整个空间。我需要使其wrap_content。 我需要这样的东西:

enter image description here

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)