gpt4 book ai didi

android - 抽屉导航标题未隐藏

转载 作者:行者123 更新时间:2023-11-29 17:16:46 24 4
gpt4 key购买 nike

我尝试用抽屉菜单创建一个简单的应用程序。我使用 Android Studio 创建了一个项目并选择了 Navigation Drawer Layout。我试图隐藏抽屉导航标题并将其放在工具栏上...我找到了放在工具栏上的方法,但我找不到隐藏图片中标题的红色部分。你能帮帮我吗?

navigation drawer header

这是我的布局页面xml代码

<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

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

关于android - 抽屉导航标题未隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38497805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com