2017-04-26 2 views
1

J'ai mon tiroir de navigation et je dois l'ouvrir, mais je ne peux pas >>de navigation n'a pas commencé

Voici mon drawer_layout.xml:

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<!-- This LinearLayout represents the contents of the screen --> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <!-- The ActionBar displayed at the top --> 
    <include 
     layout="@layout/activity_display" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <!-- The main content view where fragments are loaded --> 
    <FrameLayout 
     android:id="@+id/flContent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</LinearLayout> 

<!-- The navigation drawer that comes from the left --> 
<!-- Note that `android:layout_gravity` needs to be set to 'start' --> 
<android.support.design.widget.NavigationView 
    android:id="@+id/nvView" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="right" 
    android:background="@android:color/white" 
    app:menu="@menu/drawer_view" /> 

et ce est ma barre d'outils en activity_display.xml:

<android.support.v7.widget.Toolbar 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:id="@+id/myToolBar" 
    android:background="@color/top_bar_backgroung"> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/dots_vertical" 
     android:textSize="40sp" 
     android:layout_marginRight="10dp" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:id="@+id/openDrawer" 
     /> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="60dp" 
     android:src="@drawable/logo" 
     android:scaleType="centerInside"/> 
</android.support.v7.widget.Toolbar> 

et voici comment j'ouvrir mon tiroir:

private DrawerLayout mDrawer; 
private Toolbar toolbar; 
private NavigationView nvDrawer; 

toolbar = (Toolbar) findViewById(R.id.myToolBar); 
    setSupportActionBar(toolbar); 



    // Find our drawer view 
    View viewDrawer = getLayoutInflater().inflate(R.layout.drawer_layout, null); 
    mDrawer = (DrawerLayout) viewDrawer.findViewById(R.id.drawer_layout); 
    nvDrawer = (NavigationView) viewDrawer.findViewById(R.id.nvView); 
    setupDrawerContent(nvDrawer); 
    //gridView = (GridView) findViewById(R.id.displayGridView); 



    drawer.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Log.i(TAG, "onClick: "); 
      mDrawer.openDrawer(GravityCompat.END); 
     } 
    }); 

private void setupDrawerContent(NavigationView navigationView) { 
    navigationView.setNavigationItemSelectedListener(
      new NavigationView.OnNavigationItemSelectedListener() { 
       @Override 
       public boolean onNavigationItemSelected(MenuItem menuItem) { 
        selectDrawerItem(menuItem); 
        return true; 
       } 
      }); 
} 

public void selectDrawerItem(MenuItem menuItem) { 
    // Create a new fragment and specify the fragment to show based on nav item clicked 
    android.support.v4.app.Fragment fragment1 = null; 
    Class fragmentClass = null; 
    switch(menuItem.getItemId()) { 
     case R.id.nav_home_fragment: 
      Toast.makeText(this, "home", Toast.LENGTH_SHORT).show(); 
      //fragmentClass = FirstFragment.class; 
      break; 
     case R.id.nav_personal_fragment: 
      //fragmentClass = SecondFragment.class; 
      break; 
     case R.id.nav_avilableCareer_fragment: 
      //fragmentClass = ThirdFragment.class; 
      break; 
     case R.id.nav_declareCareer_fragment: 
      //fragmentClass = FourdFragment.class; 
      break; 
     default: 
      //fragmentClass = FirstFragment.class; 
    } 

    try { 
     fragment = (Fragment) fragmentClass.newInstance(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    // Insert the fragment by replacing any existing fragment 
    FragmentManager fragmentManager = getSupportFragmentManager(); 
    fragmentManager.beginTransaction().replace(R.id.flContent, fragment1).commit(); 

    // Highlight the selected item has been done by NavigationView 
    menuItem.setChecked(true); 
    // Set action bar title 
    setTitle(menuItem.getTitle()); 
    // Close the navigation drawer 
    mDrawer.closeDrawers(); 
} 

je ne sais pas pourquoi je ne peux pas commencer mon tirage de navigation .. je ne peux pas le voir à l'écran.

Répondre

0

fin d'écriture au lieu de droite dans le fichier xml

android:layout_gravity="right" 

à

android:layout_gravity="end" 

ou solution de rechange

utilisation

mDrawer.openDrawer(GravityCompat.RIGHT); 

au lieu de

mDrawer.openDrawer(GravityCompat.END); 
+0

c'était comme ça avant de le changer, mais ça ne marche pas –