2016-08-31 8 views
1

ナビゲーション・ドロワーを実装しようとしています。ページがロードされ、ハンバーガー・アイコンが表示される問題があります。しかし、アイコンをクリックすると、いつものように矢印に変わりますが、引き出しが表示されません。私がフラグメントの1つを強制的にデフォルトで表示しようとすると、クラスフラグメントエラーが発生するエラーが発生します。以下はナビゲーション・ドロワーが表示されず、クラス・フラグメントを拡張するエラーが発生する

引き出し以下

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    tools:context=".app.index"> 

    <include layout="@layout/toolbar"> 
    </include> 

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

     <!-- The main content view --> 
     <FrameLayout 
      android:id="@+id/content_frame" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <!-- The navigation drawer --> 
     <fragment 
      android:id="@+id/nav_drwr_fragment" 
      class="com.mobile.map.mapversion20.helpers.NavDrawerManager" 
      android:layout_width="280dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      app:layout="@layout/nav_drawer_layout" 
      tools:layout="@layout/nav_drawer_layout"/> 

    </android.support.v4.widget.DrawerLayout> 

</LinearLayout> 

を保持している私のページレイアウトでダウンここ

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <RelativeLayout 
     android:id="@+id/nav_header_container" 
     android:layout_width="match_parent" 
     android:layout_height="160dp" 
     android:background="@color/colorPrimary"> 

     <ImageView 
      android:layout_width="70dp" 
      android:layout_height="70dp" 
      android:layout_centerInParent="true" 
      android:scaleType="fitCenter" 
      android:src="@drawable/ic_profile"/> 

    </RelativeLayout> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/drawerList" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp"/> 
</LinearLayout> 

私の引き出しのレイアウトである私のフラグメントマネージャは、問題はあなたが必要です

public class NavDrawerManager extends Fragment 
{ 
    private ActionBarDrawerToggle mDrawerToggle; 
    private DrawerLayout mDrawerLayout; 
    private static boolean isLaunch = true; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    { 
     View view = inflater.inflate(R.layout.nav_drawer_layout, container, false); 

     setUpRecyclerView(view); 

     return view; 
    } 
    private void setUpRecyclerView(View view) { 

     RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.drawerList); 

     NavDrawerAdapter adapter = new NavDrawerAdapter(getActivity(), drawerItem.getData()); 
     NavDrawerManager manager = new NavDrawerManager(); 
     recyclerView.setAdapter(adapter); 
     recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); 

     if(isLaunch) 
     { 
      isLaunch = false; 
      manager.selectItem("DashBoard"); 
     } 
    } 


    public void setUpDrawer(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) { 
     mDrawerLayout = drawerLayout; 
     mDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { 
      @Override 
      public void onDrawerOpened(View drawerView) { 
       super.onDrawerOpened(drawerView); 
//    getActivity().invalidateOptionsMenu(); 
      } 

      @Override 
      public void onDrawerClosed(View drawerView) { 
       super.onDrawerClosed(drawerView); 
//    getActivity().invalidateOptionsMenu(); 
      } 

      @Override 
      public void onDrawerSlide(View drawerView, float slideOffset) { 
       super.onDrawerSlide(drawerView, slideOffset); 
       // Do something of Slide of Drawer 
      } 
     }; 

     mDrawerLayout.setDrawerListener(mDrawerToggle); 

     mDrawerLayout.post(new Runnable() { 
      @Override 
      public void run() { 
       mDrawerToggle.syncState(); 
      } 
     }); 
    } 
    public void selectItem(String title) 
    { 
     FragmentManager fragmentManager = getChildFragmentManager(); 

     switch (title) 
     { 
      case "Dashboard": 
       Fragment dashFragment = new dashboard(); 
         fragmentManager.beginTransaction() 
         .replace(R.id.content_frame,dashFragment) 
         .commit(); 
       break; 
      case "Profile": 
       Fragment profileFragment = new profile(); 
       fragmentManager.beginTransaction() 
         .replace(R.id.content_frame,profileFragment) 
         .commit(); 
       break; 
      case "Notifications": 
       Fragment notificationsFragment = new notifications(); 
       fragmentManager.beginTransaction() 
         .replace(R.id.content_frame,notificationsFragment) 
         .commit(); 
       break; 
      case "Contact": 
       Fragment contactFragment = new contact(); 
       fragmentManager.beginTransaction() 
         .replace(R.id.content_frame,contactFragment) 
         .commit(); 
       break; 
      default: 
       Fragment defaultFrag = new dashboard(); 
       fragmentManager.beginTransaction() 
         .replace(R.id.content_frame,defaultFrag) 
         .commit(); 
       break; 
     } 
    } 
} 
+0

あなたはここでエラーlogcatを投稿することができますか? – Ironman

答えて

0

ですDrawerLayoutを次のようなレイアウトファイルの親として作成します:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!-- The main content view --> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <include layout="@layout/toolbar"/> 

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

    </LinearLayout> 

    <!-- The navigation drawer --> 
    <fragment 
     android:id="@+id/nav_drwr_fragment" 
     class="com.mobile.map.mapversion20.helpers.NavDrawerManager" 
     android:layout_width="280dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:layout="@layout/nav_drawer_layout" 
     tools:layout="@layout/nav_drawer_layout"/> 

</android.support.v4.widget.DrawerLayout> 

関連する問題