Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 1.4 Navigation Drawer

I'm new to Android App developing. Today I tried to update my app to android new material design. So I used Android studio (1.4) navigation Drawer Activity. Problem is I cant understand how to use navigation bar to navigate between my actives. It different from online tutorials I seen. It dosen't use Fragments. I can change names, icons .. etc the problem is I cant understand how to navigate between activities using navigation drawer ?

thank you

 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;
}
like image 932
APP Bird Avatar asked Oct 05 '15 15:10

APP Bird


1 Answers

I had the same problem but got fixed.

Follow the steps below:

1.open the "content_main.xml" file located in the "layout" folder.

2.use the code below:

<?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>
  1. go to the "onNavigationItemSelected" method:
   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;
like image 185
L.L. Avatar answered Nov 18 '22 03:11

L.L.