How to put navigation drawer below toolbar?

前端 未结 9 2050
轮回少年
轮回少年 2021-01-02 08:17

Here my navigation drawer is above toolbar.I also added some xml code.Please help me.

here is my activity.xml



        
9条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 08:53

    certainly android:layout_marginTop="?attr/actionBarSize" do the job in

    
    

    But the problem is drawerlayout is top of the toolbar. That is why the fading here. you can remove fading by

    mDrawerLayout.setScrimColor(getResources().getColor(android.R.color.transparent));
    

    But on some devices it may look wired.

    Solution

    When working with Android studio. We can create NavigationDrawerActiviity There are 3 files named

    activity_main.xml

    app_bar_main.xml

    nav_header_main.xml

    content_main.xml

    So we can skip app_bar_main.xml and we can remove the fading.

    Step 1

    Make the root view of the activity main as Vertical LinearLayout

    
    
    

    In activity_main.xml add DrawerLayout and include content_main.xml in DrawerLayout. and Add AppBarLayout above the DrawerLayout.

    
        
    
            
    
            
    
        
        
        
            
    
            
        
    
    
    

    Step 2

    add and replace setContentView() of NavigationDrawerActiviity to

    setContentView(R.layout.activity_main);
    

    Finally we have

提交回复
热议问题