disable ActionBar Animation - Android User Interface

Android examples for User Interface:ActionBar

Description

disable ActionBar Animation

Demo Code


import android.content.res.Resources;
import android.os.Build;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.appcompat.R;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.lang.reflect.Field;

public class Main{
    public static void disableActionBarAnimation(ActionBar actionBar) {
        try {// w ww.ja va2  s .c o m
            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);
            } catch (Exception e) {
                // ....
            }
        }
    }
}

Related Tutorials