Hamburger menu spin to arrow on new activity

后端 未结 2 887
情书的邮戳
情书的邮戳 2021-02-03 10:25

I\'ve noticed that with the more recent Gmail updates for Android, when you click on one of your emails, a new Activity opens (I\'m assuming it\'s not a fragment because of the

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-03 10:54

    It too late but i put it here for upcoming questions. Gmail app opens email in a fragment.Cause you can still use hamburger menu in this page.Changing hamburger menu icon to back button i use this code and it works fine.

      public void setupToolbarNavigation() {
        toggle.setDrawerIndicatorEnabled(false);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        toggle.setToolbarNavigationClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
    
                onBackPressed();
                reverseToolbar();
    
    
            }
        });
    }
    
     public void reverseToolbar() {
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        getSupportActionBar().setHomeButtonEnabled(false);
        toggle.setDrawerIndicatorEnabled(true);
        toggle.setToolbarNavigationClickListener(null);
    }
    

    toggle is instance of ActionBarDrawerToggle which you can initiate it with this code in your activity

    toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();
    

    reverseToolbar change toolbar back icon to hamburger menu icon when user clicked.Declare this method in your activity and for replacing icon in fragment put this code to your fragment. ((YourActivity)getActivity()).setupToolbarNavigation

提交回复
热议问题