0

I've search anywhere but I haven't found it. Anything I've found this far is always hiding the Action Bar when a ListView, GridView or RecyclerView is scrolled. What I need is how to hide the Action Bar when a ViewGroup (using ScrollView for example) is scrolled? Because I can't really convert my layout to any of those three, and there is no onScrollListener for ScrollView.

Thank you.

Dark Leonhart
  • 1,494
  • 2
  • 13
  • 21

2 Answers2

0

1.implement ViewTreeObserver.OnScrollChangedListener into your class, 2.Write this line into your onCreate "getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);" (without quotes) 3.Now get ActionBar Height for Hide animation as follows -

    final TypedArray mstyled = getTheme().obtainStyledAttributes(new int[]{android.R.attr.actionBarSize });
mActionBarHeight = styledAttributes.getDimension(0, 0);
mstyled.recycle();

4.Get Action Bar.

mActionBar = getActionBar();

5.Intilize scrollview.

((ScrollView)findViewById(R.id.parent)).getViewTreeObserver().addOnScrollChangedListener(this);

6.override onScrollChange and mode your method like this.

@Override
public void onScrollChanged() {
    float mfloat = ((ScrollView)findViewById(R.id.parent)).getScrollY();
    if (mfloat >= mActionBarHeight && mActionBar.isShowing()) {
        mActionBar.hide();
    } else if ( mfloat==0 && !mActionBar.isShowing()) {
        mActionBar.show();
    }
}

Hope it Helps.

AmniX
  • 653
  • 5
  • 12
0

Using

android.support.v4.widget.NestedScrollView 

instead

Scrollview. 

It worked good

Nguyễn Trung Hiếu
  • 2,004
  • 1
  • 10
  • 22