【问题标题】:Disable default animation using overridePendingTransition in fragment android在片段android中使用overridePendingTransition禁用默认动画
【发布时间】:2015-08-31 13:52:09
【问题描述】:

我有一个以 Main Activity 开头的应用程序,在按下“下一个按钮”后创建了一个新片段。

我的问题是,按下“下一步”按钮后,新片段从顶部开始动画。

我想禁用此动画,但我发现在网络上没有任何效果。

这是我发现的主要结果,但对我没有任何帮助:

Link 1

Link 2

这是我的代码的一部分: ...//内部按钮点击监听器

        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;

这是片段的主要部分:

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();
        }
.
.
.
}

如果有其他解决方案,请告诉我。 谢谢

更新:

问题是由于 ActionBar 而不是 Fragment 发生的,解决方案如下。

【问题讨论】:

  • 有人知道这个问题的答案吗?

标签: android-fragments android-animation


【解决方案1】:

好的,我找到了这个问题的答案:

我找到了HERE

解决办法是这样的:

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){
            //....
        }
    }
}

我不知道动画是从动作栏来的,所以在调用这个函数后,动画被禁用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-19
    • 1970-01-01
    • 2014-05-06
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多