Android Navigation Drawer and windowActionBarOverlay = true

前端 未结 5 1644
清酒与你
清酒与你 2021-01-30 14:30

I\'m trying to implement the new Android Navigation Drawer in my application. I have created a BaseActivity.java that handles the Drawer setup and listeners, and I have two suba

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-30 14:43

    I have created a working demo following the above guide and tested on 2.x to 5.x

    You can clone from Github

    The important thing to play around is in Main Activity

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        res = this.getResources();
    
        this.setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        { 
            ScrimInsetsFrameLayout scrimInsetsFrameLayout = (ScrimInsetsFrameLayout)
                    findViewById(R.id.linearLayout);
            scrimInsetsFrameLayout.setOnInsetsCallback(this);
        } 
    

    and the call back

    @Override
    public void onInsetsChanged(Rect insets) {
          Toolbar toolbar = this.toolbar;
            ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams)
                    toolbar.getLayoutParams();
            lp.topMargin = insets.top;
            int top = insets.top;
            insets.top += toolbar.getHeight();
            toolbar.setLayoutParams(lp);
            insets.top = top; // revert
    }
    

    Absolutely the Theme for V21 does the magic

     
    

提交回复
热议问题