Android导航抽屉所选项目完全重叠

时间:2016-07-29 10:04:58

标签: android material-design navigation-drawer

我第一次使用带有Material Design库的新导航抽屉测试应用程序。

我的问题是,当我选择一个项目时,包含该图标的整个所选项目将完全覆盖,如下图所示。 这可能是我的错误?我已经尝试了几件事,但是成功了。

enter image description here

enter image description here

这是带导航抽屉的XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">
    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.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"
        />
</android.support.v4.widget.DrawerLayout>

2 个答案:

答案 0 :(得分:0)

['eins', 'zwei', 'yep']

在@ layout / nav_header_main中,您可以创建包含导航抽屉标题部分的xml文件。

for drawer_item_background-- 在drawable文件夹中创建xml文件并粘贴到代码下面:

<include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:divider="#FFFFFF"
        android:fitsSystemWindows="true"
        android:background="@drawable/side_nav_bar"
        app:itemTextColor="#FFFFFF"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer"
        app:itemBackground="@drawable/drawer_item_background"
        />

app:菜单包含导航栏中包含的菜单项。 这可能是这样的:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="rectangle" >
            <solid android:color="@color/colorPrimary" />
        </shape>
    </item>

    <item android:top="-2dp" android:right="-2dp" android:left="-2dp">
        <shape>
            <solid android:color="@android:color/transparent" />
            <stroke
                android:width="1dp"
                android:color="#48607B" />
        </shape>

    </item>

</layer-list>

答案 1 :(得分:0)

在尝试减少外部库之后,我发现这个库是问题所在:

  

it.sephiroth.android.library.targettooltip

但我不知道如何修复它。所以我将删除这个lib。