How to use a TabLayout with Toolbar inside CollapsingToolbarLayout?

后端 未结 18 2256
逝去的感伤
逝去的感伤 2020-11-27 11:46

I am looking at the chrisbanes/cheesesquare and I am trying to put TabLayout with a Toolbar inside a CollapsingToolbarLayout, and here is my code



        
18条回答
  •  -上瘾入骨i
    2020-11-27 12:11

    The code below implements the action Expand / Collapse toolbar.

    Basically we will have a
    CoordinatorLayout (FrameLayout)
    AppBarLayout (vertical LinearLayout Which implements many of the features of stuff designs),
    CollapsingToolbarLayout (is a wrapper for Toolbar)
    ImageView and Toolbar

    
        
    
    
            
    
            
    
    
        
    
    
    
    
    
    
    
        
    
    
    
    Observation
    - FrameLayout is necessary app: layout_behavior = "@string/appbar_scrolling_view_behavior"
    -TOOLBAR Not need backgroud, insert the color in the attribute app:contentScrim = "?Attr/ColorPrimary" from our CollapsingToolbarLayout
    

    In your class

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    mCollapsingToolbarLayout = (CollapsingToolbarLayout)findViewById(R.id.collapsing_toolbar);
    mCollapsingToolbarLayout.setTitle("YourTitle");
    setSupportActionBar(toolbar);
    

提交回复
热议问题