Java 当我第一次显示动作栏(从隐藏)时,没有显示动画-如何修复?

Java 当我第一次显示动作栏(从隐藏)时,没有显示动画-如何修复?,java,android,xml,android-layout,android-activity,Java,Android,Xml,Android Layout,Android Activity,我的问题是: android.support.v7.app.ActionBar actionBar; actionBar = getSupportActionBar(); actionBar = getSupportActionBar(); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayUseLogoEnabled(f

我的问题是:

android.support.v7.app.ActionBar actionBar;
            actionBar = getSupportActionBar();
            actionBar = getSupportActionBar();
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setDisplayUseLogoEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(false);


            LayoutInflater mInflater = LayoutInflater.from(this);
            View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);

            actionBar.setCustomView(mCustomView);
            actionBar.setDisplayShowCustomEnabled(true);
actionBar.show();
如果多次显示和隐藏ActionBar,可能您已经注意到第一次显示没有设置动画。从那时起,显示和隐藏都是动画

actionBar.show();
我的问题在这个stackoverflow线程中被描述,在作为插件的部分中(这个线程不能解决我的问题)-我没有面临与这个用户相同的问题,尽管回答者的观点解释了我的问题

actionBar.show();
如何修复上述问题,以便即使是第一次显示动画也能发生?

actionBar.show();
来解释我指的动画-

actionBar.show();
看看这段youtube视频

actionBar.show();

actionBar.show();
(上面的动画可以工作,但在我的例子中,主显示动画不会出现)

actionBar.show();
我用来显示操作栏的代码如下:

android.support.v7.app.ActionBar actionBar;
            actionBar = getSupportActionBar();
            actionBar = getSupportActionBar();
            actionBar.setDisplayShowTitleEnabled(false);
            actionBar.setDisplayUseLogoEnabled(false);
            actionBar.setDisplayHomeAsUpEnabled(false);


            LayoutInflater mInflater = LayoutInflater.from(this);
            View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);

            actionBar.setCustomView(mCustomView);
            actionBar.setDisplayShowCustomEnabled(true);
actionBar.show();

actionBar.show();

简单地使用隐藏或显示函数可以实现它所说的功能,但不会“动画化”。为此,可以使用插值器

actionBar.show();
我建议您使用新的工具栏。真的很容易!ActionBar现在已被弃用。使用工具栏,您可以执行以下操作:

actionBar.show();
展出:

actionBar.show();
toolbar.animate().translation(0).setInterpolator(new DecelerateInterpolator(2)).start();
隐藏时:

actionBar.show();
toolbar.animate().translationY(-mToolbarHeight).setInterpolator(new AccelerateInterpolator(2)).start();
就我个人而言,我通过使用自定义ScrollListener为浮动操作按钮(FAB)做了类似的实现。对于工具栏,可以对其进行修改

actionBar.show();

PS:你想要实现的也被称为

我不知道你说的动画是什么意思,但听起来好像动画是隐藏的。你不能在你真正需要的时候创建ActionBar吗?我已经更新了上面的问题,在youtube上播放了一段解释这个问题的视频。我需要的时候会露出来藏起来。这对你有帮助吗?无效操作菜单();不,我已将上面建议的代码放在每个actionBar.hide()之前;或actionBar.show();问题仍然存在是的,正如在这个stackoverflow线程中所描述的,在被引用为插件的部分中(这个线程没有解决我的问题)--我没有面临与这个用户相同的问题,尽管回答者的观点解释了我的问题
actionBar.show();