Reputation: 338
I want to hide HomeAsUp in home fragment, i have used this ((MainActivity)getActivity()).hideHome(); but it's not working. I don't want to use SherlockFragmentActivity.
Is this possible to hide HomeAsUp icon without SherlockActivity? If possible then how to use it.
When i inflate the Home fragment the code as like below
switch (item.getItemId()) {
case R.id.homemenu:
// mDrawer.openDrawer(GravityCompat.START);
// getSupportActionBar().setDisplayHomeAsUpEnabled(false); // show back button
fragmentClass = Home.class;
try {
fragment = (Fragment) fragmentClass.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().setCustomAnimations(R.anim.enter_anim, R.anim.exit_anim, R.anim.pop_enter, R.anim.pop_exit).replace(R.id.activity_main_content_fragment, fragment).commit();
return true;
}
Upvotes: 3
Views: 4332
Reputation: 1651
Try Below solution:
1 - If your activity is AppCompatActivity:
((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
((AppCompatActivity)getActivity()).getSupportActionBar().setHomeButtonEnabled(false);
or - If your activity is FragmentActivity:
getActivity().getActionBar().setDisplayHomeAsUpEnabled(false);
getActivity().getActionBar().setHomeButtonEnabled(false);
Upvotes: 2