Android Studio 1.4导航抽屉

APP*_*ird 7 android android-studio navigation-drawer

我是Android App开发的新手.今天我尝试将我的应用程序更新为android新材料设计.所以我用了Android studio(1.4)导航抽屉活动.问题是我无法理解如何使用导航栏在我的活动之间导航.它与我看到的在线教程不同.它不使用碎片.我可以更改名称,图标..等问题是我无法理解如何使用导航抽屉在活动之间导航?

谢谢

 public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.

    int id = item.getItemId();

    if (id == R.id.nav_camara) {


    } else if (id == R.id.nav_gallery) {

    } else if (id == R.id.nav_slideshow) {

    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
Run Code Online (Sandbox Code Playgroud)

L.L*_*.L. 7

我有同样的问题,但得到了修复.

请按照以下步骤操作:

1.打开位于"layout"文件夹中的"content_main.xml"文件.

2.使用以下代码:

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:showIn="@layout/app_bar_main"
        tools:context=".MainActivity">    

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/mainFrame">

       </FrameLayout>

     </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
  1. 转到"onNavigationItemSelected"方法:
   public boolean onNavigationItemSelected(MenuItem item) {

        int id = item.getItemId();
        Fragment fragment = new YourFragment();

        if (id == R.id.nav_camara) {

            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.mainFrame, fragment);
            ft.commit();

        } else if (id == R.id.nav_gallery) {


        } else if (id == R.id.nav_slideshow) {


        } else if (id == R.id.nav_manage) {


        } else if (id == R.id.nav_share) {


        } else if (id == R.id.nav_send) {


        }

        //Close Drawer After Action
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);

        return true;
Run Code Online (Sandbox Code Playgroud)