我想在NavigationView布局上删除一个栏

问题描述 投票:0回答:2

我创建了一个NavigationView,它成功。但它有一个错误。我希望我可以删除这个绿色和灰色的条。(当我创建NavigationView时,它将出现...我不知道该怎么做。enter image description here这是我的代码:

xml:

 <androidx.drawerlayout.widget.DrawerLayout
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    >
    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/activity_miaoli_menu"
        />

</androidx.drawerlayout.widget.DrawerLayout>

菜单:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
    <item
        android:id="@+id/nav_home"
        android:icon="@drawable/ic_menu_camera"
        android:title="@string/menu_home" />
    <item
        android:id="@+id/nav_gallery"
        android:icon="@drawable/ic_menu_gallery"
        android:title="@string/menu_gallery" />   
</group>
</menu>

nav.java

 Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
     drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
     navigationView = (NavigationView) findViewById(R.id.nav_view);

    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this,
            drawerLayout, toolbar, R.string.open, R.string.close);
    drawerLayout.addDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();
    navigationView.bringToFront();

有人可以帮助我吗?预先感谢。

java android navigationview
2个回答
0
投票

在布局中为坐标布局的根子项添加layout_behavior。

app:layout_behavior="@string/appbar_scrolling_view_behavior"

-1
投票

删除app:menu =“ @ menu / activity_miaoli_menu”此行,并制作自定义导航抽屉,如下面给出的代码,为每个项目进行布局

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

        <LinearLayout
            android:background="#FFFFFF"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

                        <RelativeLayout
                            android:id="@+id/layout_home"
                            android:foreground="?android:attr/selectableItemBackground"
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="@dimen/dimen_48dp">

                            <ImageView
                                android:id="@+id/nav_home"
                                app:srcCompat="@drawable/ic_home"
                                android:layout_width="@dimen/setting_icon"
                                android:layout_height="@dimen/setting_icon"
                                android:layout_marginLeft="@dimen/padding_double"
                                android:layout_marginRight="@dimen/padding_normal"
                                android:layout_centerVertical="true"
                                android:clickable="false"
                                android:focusable="false"
                                android:tint="@color/color_f85200"
                                android:layout_gravity="center_vertical"/>
                            <TextView
                                android:layout_centerVertical="true"
                                android:layout_toRightOf="@+id/nav_home"
                                android:text="@string/title_activity_home"
                                android:textSize="16sp"
                                android:clickable="false"
                                android:focusable="false"
                                android:fontFamily="@font/sarabun_medium"
                                android:layout_marginLeft="@dimen/padding_double"
                                android:layout_gravity="center_vertical"
                                android:textColor="@color/DrawerTextColor"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content" />
                        </RelativeLayout>
               </LinearLayout>
    </com.google.android.material.navigation.NavigationView>
© www.soinside.com 2019 - 2024. All rights reserved.