Android隐藏导航视图标题
我正在开发一款android应用程序,它需要工具栏下方的抽屉布局。我已经做到了这一点,但NavigationView的标题,即状态栏24dp,即使在删除标题后仍然可见。 有没有办法消除这种情况 XML文件: 从navigationview中删除app:headerLayout=@null 像这样从onCreate开始将头部布局充气,然后将可视性设置为消失Android隐藏导航视图标题,android,material-design,Android,Material Design,我正在开发一款android应用程序,它需要工具栏下方的抽屉布局。我已经做到了这一点,但NavigationView的标题,即状态栏24dp,即使在删除标题后仍然可见。 有没有办法消除这种情况 XML文件: 从navigationview中删除app:headerLayout=@null 像这样从onCreate开始将头部布局充气,然后将可视性设置为消失 View headerView= LayoutInflater.from(this).inflate(R.layout.drawer_hea
View headerView= LayoutInflater.from(this).inflate(R.layout.drawer_header, null);
navigationView.addHeaderView(headerView);
navigationView.getHeaderView(0).setVisibility(View.GONE);
在菜单中定义组,然后使用以下命令隐藏组:
navigationView.getMenu().setGroupVisible(groupPosition, false);
此外,请删除headerLayout属性。尝试以下方法:
View headerView = navigationView.inflateHeaderView(R.layout.nav_header_home);
headerView.setVisibility(View.GONE);
并从xml中删除行app:headerLayout=@null。也可以这样尝试
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:background="@color/list_background"/>
可能是因为高度不够。为什么不使用layout=@layout/app\u bar\u home包装内容,并将下面的android:layout\u添加到抽屉布局中? 或者为了保持简单,在本例中还可以使用LinearLayout。这将更容易:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include
layout="@layout/app_bar_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.NavigationView
android:paddingBottom="0dp"
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@null"
app:menu="@menu/activity_home_drawer"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
已经试过了,运气不好。顺便说一下,你看到抽屉里最上面的灰色条了。这就是问题所在。如何使其半透明?是否已将标题布局的背景色更改为透明?是否会使其变得不同?甚至我们都在将可见性设置为Gone?好的,让我看看java代码,其中您正在使用HeaderViewHeaderView=LayoutInflater.fromthis.inflateR.layout.drawer\u header,null;navigationView.AddHeaderServiceWheaderView;navigationView.GetHeadServiceW0.setVisibilityView.GONE;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include
layout="@layout/app_bar_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.NavigationView
android:paddingBottom="0dp"
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@null"
app:menu="@menu/activity_home_drawer"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>