如何在不使用碎片的情况下将导航抽屉连接到活动



我正在尝试将导航抽屉连接到活动。我已经有一些"活动"扩展了AppCompatActivity。但在教程中,要连接导航抽屉的活动应该扩展Fragments。有什么办法绕过这个问题吗?

@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.home) {
Intent secIntent = new Intent(this, SecondActivity.class);
startActivity(homeIntent);
} else if (id == R.id.livestream) {
Intent nextIntent = new Intent(this, NextActivity.class);
startActivity(nextIntent);
}
mDrawer = findViewById(R.id.drawer_layout);
mDrawer.closeDrawer(GravityCompat.START);
return true;
}

只需使用intent来更改导航抽屉中的每个活动,但使用活动的结果是导航仅在按下导航的活动中,您应该在操作栏中使用setDisplayHomeAsUpEnabled(true),以便于返回MainActivity

最新更新