2015-09-12 2 views

ответ

2

Да, это возможно. Просто посмотрите пример приложения. Это содержит CustomContainerActivity который демонстрирует, как вы можете иметь Drawer, которая находится ниже Toolbar

public class CustomContainerActivity extends AppCompatActivity { 

    //save our header or result 
    private Drawer result = null; 

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

     // Handle Toolbar 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setTitle(R.string.drawer_item_custom_container_drawer); 

     //Create the drawer 
     result = new DrawerBuilder(this) 
       //this layout have to contain child layouts 
       .withRootView(R.id.drawer_container) 
       .withToolbar(toolbar) 
       .withActionBarDrawerToggleAnimated(true) 
       .addDrawerItems(
         new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home), 
         new PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad), 
         new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye), 
         new SectionDrawerItem().withName(R.string.drawer_item_section_header), 
         new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog), 
         new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false), 
         new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github), 
         new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn) 
       ) 
       .withSavedInstance(savedInstanceState) 
       .build(); 
    } 

    @Override 
    protected void onSaveInstanceState(Bundle outState) { 
     //add the values which need to be saved from the drawer to the bundle 
     outState = result.saveInstanceState(outState); 
     super.onSaveInstanceState(outState); 
    } 

    @Override 
    public void onBackPressed() { 
     //handle the back press :D close the drawer first and if the drawer is closed close the activity 
     if (result != null && result.isDrawerOpen()) { 
      result.closeDrawer(); 
     } else { 
      super.onBackPressed(); 
     } 
    } 
} 

Также обратите внимание на другой макет XML, который используется в этом Activity.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:gravity="center" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     android:elevation="4dp" /> 

    <!-- the layout which will contain (host) the drawerLayout --> 
    <FrameLayout 
     android:layout_below="@id/toolbar" 
     android:id="@+id/drawer_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <!-- the layout which will be the content of the activity (which will be hosted inside the drawer (NOT the list of the drawer)) --> 
     <FrameLayout 
      android:id="@+id/frame_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <TextView 
       android:id="@+id/txtLabel" 
       android:layout_gravity="center" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Test" 
       android:textSize="16sp" /> 
     </FrameLayout> 
    </FrameLayout> 
</RelativeLayout> 

Это будет производить следующее:

CustomContainerActivity MaterialDrawer

+0

Он работает. Я приму ответ, как только это станет возможным. Ты был так быстр, спасибо! – zatziky

+0

ok great :) спасибо – mikepenz