2016-07-27 94 views
0

我目前有一個現有項目,我希望在其中實施導航抽屜活動。目前,如果我添加了一個新的導航抽屜的活動,它會生成以下佈局:將導航抽屜活動模板添加到現有項目中

Navigation Drawer Activity

然而,除了佈局上面,我想我的導航抽屜完全一樣,它看起來像默認模板一個這個(由資產淨值的標頭,等):

enter image description here

我如何去實現呢?我是Android開發新手。

編輯:我只需要改變我的應用程序的主題,以實現我想要的東西

回答

1

創建新抽屜活動:

文件 - >新建 - >活動 - >抽屜式導航活動

0
private void setupNavigationDrawer() { 
     //if you want to update the items at a later time it is recommended to keep it in a variable 
     PrimaryDrawerItem item1 = new PrimaryDrawerItem().withIdentifier(0).withName(R.string.drawer_item_home).withIcon(getResources().getDrawable(R.drawable.ic_home_white_24dp)); 
     PrimaryDrawerItem item2 = new PrimaryDrawerItem().withIdentifier(1).withName(R.string.drawer_item_login).withIcon(getResources().getDrawable(R.drawable.ic_account_circle_white_24dp)); 
     PrimaryDrawerItem item3 = new PrimaryDrawerItem().withIdentifier(2).withName(R.string.drawer_item_movies).withIcon(getResources().getDrawable(R.drawable.ic_movie_white_24dp)); 
     PrimaryDrawerItem item4 = new PrimaryDrawerItem().withIdentifier(3).withName(R.string.drawer_item_trailers).withIcon(getResources().getDrawable(R.drawable.ic_videocam_white_24dp)); 
     PrimaryDrawerItem item5 = new PrimaryDrawerItem().withIdentifier(4).withName(R.string.drawer_item_theatres).withIcon(getResources().getDrawable(R.drawable.ic_theaters_white_24dp)); 
     PrimaryDrawerItem item6 = new PrimaryDrawerItem().withIdentifier(5).withName(R.string.drawer_item_location).withIcon(getResources().getDrawable(R.drawable.ic_location_on_white_24dp)); 
     SecondaryDrawerItem item7 = (SecondaryDrawerItem) new SecondaryDrawerItem().withIdentifier(6).withName(R.string.drawer_item_about_us).withIcon(FontAwesome.Icon.faw_info_circle); 
     SecondaryDrawerItem item8 = (SecondaryDrawerItem) new SecondaryDrawerItem().withIdentifier(7).withName(R.string.drawer_item_contact_us).withIcon(FontAwesome.Icon.faw_whatsapp); 
     SecondaryDrawerItem item9 = (SecondaryDrawerItem) new SecondaryDrawerItem().withIdentifier(8).withName(R.string.drawer_item_feedback).withIcon(FontAwesome.Icon.faw_commenting); 
     SecondaryDrawerItem item10 = (SecondaryDrawerItem) new SecondaryDrawerItem().withIdentifier(9).withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_wrench); 

     // Create the AccountHeader 
     AccountHeader headerResult = new AccountHeaderBuilder() 
       .withActivity(this) 
       .withHeaderBackground(R.color.colorMaterialDark) 
       .addProfiles(
         new ProfileDrawerItem().withName(getResources().getString(R.string.app_name)).withEmail(getResources().getString(R.string.email_id)).withIcon(getResources().getDrawable(R.drawable.profile)) 
       ) 
       .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() { 
        @Override 
        public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) { 
         //Any activity or Intent 
        } 
       }) 
       .build(); 
     //Create the drawer and remember the `Drawer` result object 
     Drawer result = new DrawerBuilder() 
       .withActivity(this) 
       .withAccountHeader(headerResult) 
       .withToolbar(toolbar) 
       .addDrawerItems(
         item1, item2, item3, item4, item5, item6, 
         new SectionDrawerItem().withName("Extras"), 
         item7, item8, item9, item10 
       ) 

       //Set onClick options for drawer item click 
       .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { 
        @Override 
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { 
         // do something with the clicked item :D 
         switch (position) { 
          //Home 
          case 1: { 
           break; 
          } 
          //Login 
          case 2: { 

           //Login Activity 
           break; 
          } 

          case 3: { 
           //Third activity 
           break; 
          } 

          case 4: { 
           break; 
          } 

          case 5: { 

           break; 

          } 
          //Location 
          case 6: { 

           break; 
          } 
          //About us 
          case 8: { 
           break; 
          } 
          //Contact Us 
          case 9: { 

           break; 
          } 
          //Feedback 
          case 10: { 

           break; 
          } 
          //Settings 
          case 11:{ 

           break; 
          } 

         } 
         return true; 
        } 
       }) 
       .build(); 

     result.addStickyFooterItem(new PrimaryDrawerItem().withName("Visit us again")); //Adding footer to nav drawer 
    } 

你將不得不添加以下行到android studio中的build.gradle文件

compile('com.mikepenz:materialdrawer:[email protected]') { 
    transitive = true 
} 
compile 'com.mikepenz:fontawesome-typeface:[email protected]'