2017-02-21 164 views
2

当可折叠工具栏展开时它工作良好,但当我向上滚动以使其折叠到工具栏中时,工具栏仅显示我的应用程序名称。我希望它也显示汉堡切换。如何折叠折叠工具栏时导航栏切换?

代码:

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
       this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
     drawer.setDrawerListener(toggle); 
     toggle.syncState(); 

     NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
     navigationView.setNavigationItemSelectedListener(this); 
} 

回答

0

发生了什么事是你的工具栏并没有被告知绘制图标的标题左侧的。当您的工具栏展开后,CollapsingToolbarLayout会告知工具栏有图标。

所以,如果你希望你的工具栏有标题的左边的图标,你可以这样做:

getSupportActionBar().setDisplayShowHomeEnabled(true); 

你通常并不需要这样做,因为活动将告诉动作条如果活动具有父活动,则显示该图标。因此,我怀疑你的情况是我们正在谈论你的启动器活动。

希望这会有所帮助。

0

我找到了解决方案。我已将可折叠工具栏中的工具栏设置为应该固定的视差。

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    app:layout_collapseMode="pin" />