2016-09-06 2 views
1

Мои взгляды ящика не показывая, что работает нормально, прежде чем я не сделал каких-либо изменений в макете или MainActivity теперь, когда им не проверяя его, показывая ничеговыдвижных просмотров не показывая

Мой XML

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
android:orientation="vertical"> 

<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#71b6ca" 
    android:id="@+id/toolbar" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:title="DocVids" /> 

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

<FrameLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/containerView"> 
</FrameLayout> 



<android.support.design.widget.NavigationView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:layout_marginTop="-24dp" 
    android:id="@+id/mynav" 
    /> 
</android.support.v4.widget.DrawerLayout> 

</LinearLayout> 

Ящика меню

<item android:title="FeedBack" 
     android:id="@+id/nav_item_feedback" 
     android:icon="@drawable/feedback_icon"/> 

<item android:title="Rate Us" 
     android:id="@+id/nav_item_draft" 
     android:icon="@drawable/rateus_icon"/> 



<item android:title="Others"> 
    <menu> 
     <item 
      android:title="About" 
      android:icon="@drawable/about_icon"/> 
     <item android:title="Help" 
      android:icon="@drawable/help"/> 
    </menu> 
</item> 

MainActivity

public class MainActivity extends AppCompatActivity{ 
DrawerLayout mDrawerLayout; 
NavigationView mNavigationView; 
FragmentManager mFragmentManager; 
FragmentTransaction mFragmentTransaction; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 


    setTitle("DocVids"); 
    /** 
    *Setup the DrawerLayout and NavigationView 
    */ 

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); 
    mDrawerLayout.bringToFront(); 
    mNavigationView = (NavigationView) findViewById(R.id.mynav) ; 

    /** 
    * Lets inflate the very first fragment 
    * Here , we are inflating the TabFragment as the first Fragment 
    */ 

    mFragmentManager = getSupportFragmentManager(); 
    mFragmentTransaction = mFragmentManager.beginTransaction(); 
    mFragmentTransaction.replace(R.id.containerView,new TabFragment()).commit(); 
    /** 
    * Setup click events on the Navigation View Items. 
    */ 

    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { 
     @Override 
     public boolean onNavigationItemSelected(MenuItem menuItem) { 
      mDrawerLayout.closeDrawers(); 



      if (menuItem.getItemId() == R.id.nav_item_feedback) { 
       FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction(); 
       fragmentTransaction.replace(R.id.containerView,new FeedBack()).commit(); 

      } 

      if (menuItem.getItemId() == R.id.nav_item_fav) { 
       FragmentTransaction xfragmentTransaction = mFragmentManager.beginTransaction(); 
       xfragmentTransaction.replace(R.id.containerView,new TabFragment()).commit(); 
      } 

      return false; 
     } 

    }); 


    /** 
    * Setup Drawer Toggle of the Toolbar 
    */ 

    android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar); 
    ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, toolbar,R.string.app_name, 
      R.string.app_name); 

    mDrawerToggle.syncState(); 
    //mDrawerLayout.setDrawerListener(mDrawerToggle); 
    mDrawerLayout.addDrawerListener(mDrawerToggle); 

} 

ответ

0

Вы должны поставить макет ящика в качестве родительского элемента, поэтому ваш макет станет

<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/drawerLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#71b6ca" 
    > 
    <LinearLayout 

     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     android:orientation="vertical"> 

     <android.support.v7.widget.Toolbar 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#71b6ca" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      app:title="DocVids"/> 


     <FrameLayout 
      android:id="@+id/containerView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 
     </FrameLayout> 

     <android.support.design.widget.NavigationView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/mynav" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:layout_marginTop="-24dp" 
      app:menu="@menu/drawer"//Your drawer menu consisting of menu items 
     /> 
    </LinearLayout> 

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

Регулярно проверяйте this пример, чтобы получить больше информации об использовании меню навигации

+0

давая ошибку на этом –

+0

какие ошибки вы получаете? –

+0

Я получил свою ошибку, я просто непреднамеренно удалил меню и некоторые другие вещи из XML теперь его обратно с тем же линейным расположением, что и родительский вид –

2

В вашем Моего XML Сделать XML для навигации ящик, как это: Сделать DrawerLayout в качестве родительского макета

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

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_home" 
    app:menu="@menu/activity_home_drawer" /> 

</android.support.v4.widget.DrawerLayout> 
Смежные вопросы