remove line divider from NavigationView android

情到浓时终转凉″ 提交于 2019-12-11 00:20:09

问题


i have this menu for the NavigationView of layout:

<item android:title="title1">
    <menu>
        <item
            android:id="@+id/nav_tab1"
            android:icon="@drawable/ic_action_nav_tab1"
            android:title="test1" />
        <item
            android:id="@+id/nav_tab2"
            android:icon="@drawable/ic_action_nav_tab2"
            android:title="test2" />
    </menu>
</item>
<item android:title="title2">
    <menu>
        <item
            android:id="@+id/nav_settings"
            android:icon="@drawable/ic_action_settings"
            android:title="test3" />
    </menu>
</item>

how can remove the line divider from menu?


回答1:


Add this to your Styles:

<item name="android:listDivider">@android:color/transparent</item>

Here you can read more about it: How can I change separator color in NavigationView?




回答2:


I had same problem with BottomNavigationView. Maybe someone will find my solution usefull.

Reason of this divider on android devices with API < 21 is this code snippet in BottomNavigationView sources:

if (VERSION.SDK_INT < 21) {
    this.addCompatibilityTopDivider(context);
}

addCompatibilityTopDivider(context) method:

private void addCompatibilityTopDivider(Context context) {
    View divider = new View(context);
    divider.setBackgroundColor(ContextCompat.getColor(context, color.design_bottom_navigation_shadow_color));
    LayoutParams dividerParams = new LayoutParams(-1, this.getResources().getDimensionPixelSize(dimen.design_bottom_navigation_shadow_height));
    divider.setLayoutParams(dividerParams);
    this.addView(divider);
}

My solution was to override design_bottom_navigation_shadow_color in colors.xml, like this:

<color name="design_bottom_navigation_shadow_color" tools:override="true">#00000000</color>

And it works:)




回答3:


<group android:id="@+id/menu_top">
<item android:title="title1">
    <menu>
        <item
            android:id="@+id/nav_tab1"
            android:icon="@drawable/ic_action_nav_tab1"
            android:title="test1" />
        <item
            android:id="@+id/nav_tab2"
            android:icon="@drawable/ic_action_nav_tab2"
            android:title="test2" />
    </menu>
</item>
<item android:title="title2">
    <menu>
        <item
            android:id="@+id/nav_settings"
            android:icon="@drawable/ic_action_settings"
            android:title="test3" />
    </menu>
</item>

Try grouping these items...I haven't tried this but it should work



来源:https://stackoverflow.com/questions/35070380/remove-line-divider-from-navigationview-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!