1

I have application that start with Main Activity and after pressing on "next button a new fragment was created.

My problem is that after pressing on the "Next" button, the new fragment animated from top.

I would like to disable this animation but I found that nothing work on web.

This is the main results I found but nothing work for me :

Link 1

Link 2

This is part of my code: ...//inside button click listener

        case R.id.btnNext:

        if(Maindb.getSingleSetting("isFisrtTime").equals("true"))
        {

             String  str = Maindb.getSingleSetting("isFisrtTime");
            fragmentLanguage = new ActChooseLanguage();
            if (fragmentLanguage != null) {
                FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction()
                        .replace(R.id.frame_container, fragmentLanguage).commit();
            }
        }
        else
        {
            fragmentHome = new ActHome();
            if (fragmentHome != null) {
                FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction()
                        .replace(R.id.frame_container, fragmentHome).commit();
            }
        }
        break;

And this is main part of the fragment:

public class ActChooseLanguage  extends Fragment{
    private  View rootView ;
    DrawerLayout mDrawerLayout;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        getActivity().overridePendingTransition(0, 0);

        rootView = inflater.inflate(R.layout.activity_choose_language, container, false);


        ImageButton btnACMenu = (ImageButton) getActivity().getActionBar().getCustomView().findViewById(R.id.imgHamburger);
        btnACMenu.setVisibility(View.INVISIBLE);

        getActivity().getIntent().addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        getActivity().getActionBar().show();


        return rootView;
    }

    @Override
    public void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        }
.
.
.
}

If there are another solution please let me know. Thanks

UPDATE:

The problem happened because of the ActionBar and not the Fragment, the solution is bellow.

Community
  • 1
  • 1
user2235615
  • 1,513
  • 3
  • 17
  • 37

1 Answers1

0

Ok, I found the answer for this problem:

I found it HERE.

The solution is this:

public static void disableShowHideAnimation(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);
        }catch (Exception e){
            //....
        }
    }
}

I didn't know that the animation came from the action bar, so after calling to this function the animation was disabled.

Community
  • 1
  • 1
user2235615
  • 1,513
  • 3
  • 17
  • 37