I am trying to disable the Up button in the Support Actionbar on certain user actions. According to http://developer.android.com/reference/android/app/ActionBar.html#setHomeButtonEnabled(boolean) , setHomeButtonEnabled should do what I want. However, the button remains clickable. (I can disable the other icons in the actionbar without problem).
I am trying to disable it from a fragment. My code to disable is:
@Override
public void onPrepareOptionsMenu (Menu menu) {
if (isUpdating) {
getBaseActivity().getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.ic_backgrey));
getBaseActivity().getSupportActionBar().setHomeButtonEnabled(false);
for (int i = 0; i < menu.size(); i++) {
menu.getItem(i).setEnabled(false);
menu.getItem(i).getIcon().setAlpha(64);
}
} else {
getBaseActivity().getSupportActionBar().setHomeButtonEnabled(true);
getBaseActivity().getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.ic_back));
for (int i = 0; i < menu.size(); i++) {
menu.getItem(i).setEnabled(true);
menu.getItem(i).getIcon().setAlpha(255);
}
}
}
and my code in activity onCreate is:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.ic_back));
and my Fragment onCreate contains setHasOptionsMenu(true)
In your fragment add
getBaseActivity().getSupportActionBar().setDisplayHomeAsUpEnabled(false);
and in your Activity add
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
In oncreate() setDisplayHomeAsUpEnabled should be set to false as well.
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
http://developer.android.com/reference/android/app/ActionBar.html#setDisplayHomeAsUpEnabled(boolean)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.