我正在使用新的DrawerLayout
进行侧面导航。我正在使用这样的抽屉图标('汉堡包'):
@Override
protected void onStart() {
super.onStart();
mDrawerLayout = (DrawerLayout) findViewById(R.id.activity_main_drawerlayout);
mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
R.drawable.ic_navigation_drawer,
R.string.app_name,
R.string.app_name);
mDrawerLayout.setDrawerListener(mDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
但是,当我向backstack添加Fragment
时,我想再次显示后退箭头,这样用户就可以导航回“home”,然后再打开app抽屉。
如何将抽屉图标重置为后退图标?
我想要的箭头:
答案 0 :(得分:72)
要禁用和隐藏DrawerToggle“Hamburger”,只需调用
即可mDrawerToggle.setDrawerIndicatorEnabled(false);
答案 1 :(得分:2)
我为托管活动创建了一个界面来更新汉堡包菜单的视图状态。对于顶级片段,我将切换设置为true
,并将片段设置为我要显示的< arrow我将切换设置为false
。
public class SomeFragment extends Fragment {
public interface OnFragmentInteractionListener {
public void showDrawerToggle(boolean showDrawerToggle);
}
private OnFragmentInteractionListener mListener;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
this.mListener = (OnFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener");
}
}
@Override
public void onResume() {
super.onResume();
mListener.showDrawerToggle(false);
}
}
然后在我的活动中......
public class MainActivity extends Activity implements SomeFragment.OnFragmentInteractionListener {
private ActionBarDrawerToggle mDrawerToggle;
public void showDrawerToggle(boolean showDrawerIndicator) {
mDrawerToggle.setDrawerIndicatorEnabled(showDrawerIndicator);
}
}