Android, DrawerLayout + Fragments + CollapsingToolbarLayout

前端 未结 3 1227
一生所求
一生所求 2020-12-29 12:23

Is it possible to have a CoordinatorLayout / CollapsingToolbarLayout in the fragments shown in the main container of a DrawerLayout?

An answer to another question su

3条回答
  •  青春惊慌失措
    2020-12-29 13:15

    This layout works for me

    
    
    
    
    
    
        
    
            
    
        
    
        
    
    
    
    
    
    
    

    Initialise the activity as normal

    public class BaseDrawerActivity extends AppCompatActivity implements MenuInterface {
    
    private DrawerLayout mDrawerLayout;
    private StickyListHeadersListView menuItemListView;
    private static MenuItemAdapter menuItemAdapter;
    private ActionBarDrawerToggle mDrawerToggle;
    
    private Toolbar toolbar;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_drawer);
            mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
            menuItemListView = (StickyListHeadersListView) findViewById(R.id.drawer);
            toolbar = (Toolbar) findViewById(R.id.toolbar);
            if (savedInstanceState == null) {
    
            }
    
            mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout,toolbar,R.string.home_open,R.string.home_close);
            mDrawerLayout.setDrawerListener(mDrawerToggle);
        }
    
    
        @Override
        protected void onPostCreate(Bundle savedInstanceState) {
            super.onPostCreate(savedInstanceState);
            // Sync the toggle state after onRestoreInstanceState has occurred.
            mDrawerToggle.syncState();
    
        }
    

    This will allow you to add the usual CoordinatorLayout features.

提交回复
热议问题