Dia*_*idi 3 android fragment up-navigation actionbardrawertoggle
标题几乎是不言自明的。
建筑学:
我在替换片段之前禁用抽屉切换并将 Home As Up 指示器设置为:
mDrawerToggle.setDrawerIndicatorEnabled(false);
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
actionBar.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp);
actionBar.setDisplayHomeAsUpEnabled(true);
Run Code Online (Sandbox Code Playgroud)
然后,当单击 UP 图标时,没有任何反应。我调试了它,但没有调用 onOptionsItemSelected 方法。
仅供参考,我添加到菜单中的所有其他按钮(搜索、刷新等)都可以工作,并且 onOptionsItemSelected 会被调用。
如果您在抽屉活动中实现 onOptionsItemSelected,则它也将不再在片段中被调用,除非您在活动中返回 false。
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
return false; //The fragment will take care of it
default:
break;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你!
更新
正如我所说,您还可以尝试启动一个新活动并在活动中加载该片段。由于您已经通过 Bundle 将数据传递到子片段,因此您可以对 Activity 执行相同的操作。
Intent intent = new Intent(getActivity(), NewActivity.class);
Bundle bundle = new Bundle();
bundle.putWhatever(key, value); //There's no such method, just a generalization
intent.putExtras(bundle);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2114 次 |
| 最近记录: |