导航抽屉调用活动

时间:2017-09-07 11:18:10

标签: android navigation-drawer

如何从导航栏中调用活动。

我的导航抽屉里:

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

    if (id == R.id.nav_Home) {
        Toast.makeText(this, "Home", Toast.LENGTH_SHORT).show();
        HomeFragment homeFragment = new HomeFragment();
        FragmentManager manager  = getSupportFragmentManager();
        manager.beginTransaction().replace(R.id.RelativeLayout, homeFragment, homeFragment.getTag()).commit();

    } else if (id == R.id.nav_Profile) {
        Toast.makeText(this, "Profile", Toast.LENGTH_SHORT).show();


    } else if (id == R.id.nav_manage) {
        Toast.makeText(this, "Settings", Toast.LENGTH_SHORT).show();

    } else if (id == R.id.nav_share) {
        Toast.makeText(this, "Share", Toast.LENGTH_SHORT).show();


    } else if (id == R.id.nav_send) {
        Toast.makeText(this, "Send", Toast.LENGTH_SHORT).show();}

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

我有一个名为ProfileActivity.java的活动,但我不知道如何通过导航抽屉调用活动...帮助

1 个答案:

答案 0 :(得分:0)

你好试试这个希望它可以帮到你

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

    if (id == R.id.nav_Home) {
        Toast.makeText(this, "Home", Toast.LENGTH_SHORT).show();
        HomeFragment homeFragment = new HomeFragment();
        FragmentManager manager  = getSupportFragmentManager();
        manager.beginTransaction().replace(R.id.RelativeLayout, homeFragment, homeFragment.getTag()).commit();

    } else if (id == R.id.nav_Profile) {
        //Toast.makeText(this, "Profile", Toast.LENGTH_SHORT).show();
    startActivity(new Intent(YOUR_ACTIVITY,ProfileActivity.class));

    } else if (id == R.id.nav_manage) {
        Toast.makeText(this, "Settings", Toast.LENGTH_SHORT).show();

    } else if (id == R.id.nav_share) {
        Toast.makeText(this, "Share", Toast.LENGTH_SHORT).show();


    } else if (id == R.id.nav_send) {
        Toast.makeText(this, "Send", Toast.LENGTH_SHORT).show();}

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