当可折叠工具栏扩展时,它可以很好地工作,但是当我向上滚动以使其仅折叠到工具栏中时,工具栏只显示我的应用程序名称。我希望它也显示汉堡切换。
代码:
@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);
}
正在发生的事情是,您的工具栏根本没有被告知绘制标题左侧的图标。扩展工具栏后,collapsingtoolbarlayout将告诉工具栏具有图标。
所以,如果您希望工具栏在标题的左侧具有图标,则可以执行此操作:
getSupportActionBar().setDisplayShowHomeEnabled(true);
您通常不需要执行此操作,因为如果活动具有父活动,活动将告诉动作栏已经显示图标。因此,我怀疑您正在谈论您的发射器活动。
希望这会有所帮助。
我找到了解决方案。我已经将工具栏设置在可折叠的工具栏中,以免固定。
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />