如何在不使用 Fragments 的情况下将 Navigation Drawer 连接到 activity
How can i connect Navigation Drawer to activity without using Fragments
我正在尝试将 Navigation Drawer 连接到 activity。我已经有一些 Activity 扩展了 AppCompatActivity。但在教程中,Activity 你想要连接导航抽屉应该扩展片段。有什么办法可以解决这个问题吗?
只需使用导航抽屉中的每个 activity 更改意图,但使用 activity 的结果是导航仅在放置导航的 activity 中,您应该使用 setDisplayHomeAsUpEnabled(true)
在操作栏中,以便返回 MainActivity
@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;
}
我正在尝试将 Navigation Drawer 连接到 activity。我已经有一些 Activity 扩展了 AppCompatActivity。但在教程中,Activity 你想要连接导航抽屉应该扩展片段。有什么办法可以解决这个问题吗?
只需使用导航抽屉中的每个 activity 更改意图,但使用 activity 的结果是导航仅在放置导航的 activity 中,您应该使用 setDisplayHomeAsUpEnabled(true)
在操作栏中,以便返回 MainActivity
@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;
}