导航抽屉标题未隐藏 [英] Navigation Drawer Header is not hiding

查看:103
本文介绍了导航抽屉标题未隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Drawer Menu创建一个简单的应用程序.我使用Android Studio创建了一个项目,然后选择导航抽屉布局".我试图隐藏导航抽屉标题并将其放在工具栏上...我找到了放置工具栏的方法,但在图片中找不到标题的隐藏RED部分.你能帮我吗?

I tried to create one simple app with Drawer Menu. I created a project with Android Studio and select Navigation Drawer Layout. I'm trying to hide navigation drawer header and put it on toolbar... I found the way to put on toolbar but I can't find hide RED part of header in picture. Can you help me please.

这是我的布局页面xml代码

Here is my layout page xml codes

<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"
    android:layout_marginTop="?attr/actionBarSize" //With this code i put menu under toolbar
    app:menu="@menu/activity_main_drawer" />

 </android.support.v4.widget.DrawerLayout>

这是我的MainActivity.java

Here is my MainActivity.java

public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);


}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}



@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    FragmentManager fragmentManager = getFragmentManager();

    if (id == R.id.nav_first_layout) {
        fragmentManager.beginTransaction().replace(R.id.content_frame,new FirstFragment()).commit();
    } else if (id == R.id.nav_second_layout) {
        fragmentManager.beginTransaction().replace(R.id.content_frame,new SecondFragment()).commit();
    } else if (id == R.id.nav_third_layout) {
        fragmentManager.beginTransaction().replace(R.id.content_frame,new ThirdFragment()).commit();
    }   else if (id == R.id.nav_home) {
        Intent intent = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(intent);
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
}

如何隐藏红色部分?

推荐答案

在xml中的 android.support.design.widget.NavigationView 下设置fitsystemwindow=false.

这篇关于导航抽屉标题未隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆