2016-02-23 46 views
0

在Android Studio中创建新项目时Android Studio会提示Activity。 导航抽屉活动我希望抽屉切换显示,但默认模式下它隐藏在导航下。Android Studio NavigationDrawer

enter image description here

enter image description here

这是我的代码:

setContentView(R.layout.activity_main); 
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); 
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
drawer.setDrawerListener(toggle); 
toggle.syncState(); 

请帮助这一变化也表明抽屉切换...

+0

请发表您的活动代码 – Rohit5k2

+0

这个默认的代码我的朋友...: 的setContentView(R.layout.activity_main); 工具栏工具栏=(工具栏)findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer =(DrawerLayout)findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this,drawer,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); –

+4

看到这个http://stackoverflow.com/questions/26464326/how-do-i-make-drawerlayout-to-display-below-the-toolbar – Rohit5k2

回答

1

我做activity_main.xml中

变化

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:orientation="vertical" 
    android:layout_height="match_parent"> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolBar" 
     android:layout_width="match_parent" 
     android:background="#adfcdd" 
     android:layout_height="50dp"></android.support.v7.widget.Toolbar> 
</LinearLayout> 
    <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_main" 
      app:menu="@menu/activity_main_drawer" /> 

    </android.support.v4.widget.DrawerLayout> 
</LinearLayout> 
+0

WOWWWW谢谢很多这解决了我的问题.... –

+0

然后标记它是正确的,并给它投票。 –

+0

其我的快乐 –