By default in Android 3.0+, when ActionBar.hide()/show() are called the bar is animated with a brief fade in/out animation.
There does not seem to be an XML style attri
if you use support-v7-compat, you can disable hide animation like this:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//消除动画效果
disableABCShowHideAnimation(getSupportActionBar());
return super.onCreateOptionsMenu(menu);
}
public static void disableABCShowHideAnimation(ActionBar actionBar) {
try
{
actionBar.getClass().getDeclaredMethod("setShowHideAnimationEnabled", boolean.class).invoke(actionBar, false);
}
catch (Exception exception)
{
try {
Field mActionBarField = actionBar.getClass().getSuperclass().getDeclaredField("mActionBar");
mActionBarField.setAccessible(true);
Object icsActionBar = mActionBarField.get(actionBar);
Field mShowHideAnimationEnabledField = icsActionBar.getClass().getDeclaredField("mShowHideAnimationEnabled");
mShowHideAnimationEnabledField.setAccessible(true);
mShowHideAnimationEnabledField.set(icsActionBar,false);
Field mCurrentShowAnimField = icsActionBar.getClass().getDeclaredField("mCurrentShowAnim");
mCurrentShowAnimField.setAccessible(true);
mCurrentShowAnimField.set(icsActionBar,null);
//icsActionBar.getClass().getDeclaredMethod("setShowHideAnimationEnabled", boolean.class).invoke(icsActionBar, false);
}catch (Exception e){
//....
}
}
}