how to implement navigation drawer without action bar but opens the navigation screen with a button on main screen?

后端 未结 2 517
北恋
北恋 2021-01-14 13:08

navigation drawer app that have login screen on its left_drawer fragment (see link: how to show a activity(login screen) under android navigation drawer ), I want to open t

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-14 13:47

    It's quite simple actually. Easier than with ActionBar. I'm writing the answer with almost simplest of layouts

    make your xml something like this:

    
    
    
    
        
    
        

    Then make your activity something like this:

    public class MainActivity extends Activity {
    
    RelativeLayout leftRL;
    RelativeLayout rightRL;
    DrawerLayout drawerLayout;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    //      I'm removing the ActionBar.
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
    
        leftRL = (RelativeLayout)findViewById(R.id.whatYouWantInLeftDrawer);
        rightRL = (RelativeLayout)findViewById(R.id.whatYouWantInRightDrawer);
        drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
        }
    
        public  void onLeft(View view)
        {
        drawerLayout.openDrawer(leftRL);
        }
    
        public  void onRight(View view)
        {
        drawerLayout.openDrawer(rightRL);
        }
    }
    

    That's it. Hope it helps.

提交回复
热议问题