如何隐藏工具栏,而滚动列表视图吗? (就像谷歌Play商店)就像、视图、工具栏、商店

2023-09-05 06:36:27 作者:Custom(习惯)

好了,隐藏操作栏的东西是可行的。但是,我们怎样可以隐藏(新引进)的工具栏在我们的活动?

Ok, so hiding the action bar is something doable. But, how can we hide the (newly introduced) toolbar in our activity?

我正在与具有主题为theme.apcompat.light.noactionbar(隐藏操作栏)一个活动的应用程序,我已经把它下面slidingtablayout一个工具栏。和它下面是我的列表视图。

I am making an app with an activity having theme as theme.apcompat.light.noactionbar(to hide the action bar) , I have placed a toolbar with slidingtablayout below it. And below it is my listview.

我要的是隐藏的工具栏,当我滚动列表视图了。但slidingtablayout应保持在那里。虽然在,如果我向下滚动列表视图的中央,工具栏应该再次出现。

What I want is to hide the toolbar when I scroll the listview up. But the slidingtablayout should remain there. And while in middle of the listview if I scroll down, the toolbar should again be visible.

推荐答案

请参阅我的最新答案在这里使用了设计支持库

Updated (8/24/2015):

Please see my latest answer here using the Design Support Library:

Hiding在RecyclerView / ListView中的动作条onScroll

请参阅 http://stackoverflow.com/a/26547550/950427 和https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/BaseActivity.java.

mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.fragment_drawer);
mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar);
mToolbar.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        if (Build.VERSION.SDK_INT >= 16) {
            mToolbar.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        } else {
            mToolbar.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        }
        mToolbar.animate().translationY(-mToolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();
    }
});

来源: http://pastebin.com/yeMX3VYP

http://stackoverflow.com/a/17767691/950427

我最近想的相同的功能,这完美的作品对我来说:

I recently wanted the same functionality and this works perfectly for me:

当用户滚动向上,在ActionBar将隐藏在为了给用户整个屏幕一起工作的工作。

As the user scrolls upward, the ActionBar will be hidden in order to give the user the entire screen to work work with.

随着用户向下滚动,并让走,动作条会回来。

As the user scrolls downward and lets go, the ActionBar will return.

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

listView.setOnScrollListener(new OnScrollListener() {
    int mLastFirstVisibleItem = 0;

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {   }           

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {    
        if (view.getId() == listView.getId()) {
            final int currentFirstVisibleItem = listView.getFirstVisiblePosition();

            if (currentFirstVisibleItem > mLastFirstVisibleItem) {
                // getSherlockActivity().getSupportActionBar().hide();
                getSupportActionBar().hide();
            } else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
                // getSherlockActivity().getSupportActionBar().show();
                getSupportActionBar().show();
            }

            mLastFirstVisibleItem = currentFirstVisibleItem;
        }               
    }
});