Show hide fragment in android

Don’t mess with the visibility flags of the container – FragmentTransaction.hide/show does that internally for you. So the correct way to do this is: FragmentManager fm = getFragmentManager(); fm.beginTransaction() .setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out) .show(somefrag) .commit(); OR if you are using android.support.v4.app.Fragment FragmentManager fm = getSupportFragmentManager(); fm.beginTransaction() .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out) .show(somefrag) .commit();

Why my show hide button needs double-click on first time

To achieve expected result, use below option of checking display initially which will be empty if it is not inline x.style.display === “none” || x.style.display === “” Please refer this link for more details – Why element.style always return empty while providing styles in CSS? function showhidemenu() { var x = document.getElementById(“menu”); if (x.style.display === … Read more