android - 使用后退按钮更改导航抽屉按钮后无法恢复
问题描述
当我将其更改为后退按钮后返回时,它会消失并显示以下代码:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(false);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
ActionBarDrawerToggle mToggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mToggle.setDrawerIndicatorEnabled(true);
drawer.setDrawerListener(mToggle);
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
我认为该代码应该使打开菜单的导航抽屉按钮再次出现,但事实并非如此。
知道该代码中可能有什么问题,所以导航抽屉按钮再次出现?
解决方案
试试这样:
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//.....
此外,您可以使用androidx.navigation.ui.NavigationUI包来设置您的抽屉菜单。
这是关于 NavigationUI 的好文章。
推荐阅读
- c - 如何打印以小端序存储的十六进制值?
- c# - C# 调整 int 数组的大小然后显示值
- tla+ - 我如何断言 TLA+ 中有一个数字或一个列表增长?
- php - 编写双重联接以获取产品的子类别
- perl - Perl - 在找到关键字后立即获取值
- amazon-ec2 - CloudWatch 警报触发的 AutoScaling 操作的延迟
- javascript - HTML,Javascript - 单击按钮后如何保存变量
- python - 何时使用 numpy 与统计模块
- c# - 从 Web 浏览器获取 URL(URI) 地址
- angular - 即使客户端pc时间错误,如何正确检查访问令牌是否从前端过期?