Hide Actiobar smoothly on Listview scroll up

I want to hide the action bar if I scroll through the list. It should look like the new Play Store app on Android Lollipop. If I use getActionBar (). Hide () the action bar is hiding the animation, but I want to scroll the Actiobar to the top.

How it works?

Edit

I found that ActionBar can auto-hide in API level 21:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    setContentView(R.layout.activity_main);
    m_lvTest = (ListView)findViewById(R.id.lvTest);
    ArrayList<String> values = new ArrayList<String>();
    for (int i = 0; i < 100; i++) {
        values.add(i+" Item");
    }
    CustomAdapter adapter = new CustomAdapter(this, R.id.lvTest, values);
    m_lvTest.setAdapter(adapter);
    m_lvTest.setNestedScrollingEnabled(true);

    getActionBar().setHideOnContentScrollEnabled(true);
}

      

But it doesn't scroll. He animates.

+3


source to share


3 answers


As Zenco installed, for Google Play Store, as effect, try ...



  • Try this new toolbar widget introduced in Lollipop (API Level 21)
  • which is also supported by this api in earlier versions of android.
  • This Android developer blog gives a good idea of ​​how to use it.
0


source


There is a method called setHideOnContentScrollEnabled (boolean) ' ActionBar . Enable hiding the action bar in scrolling content. If enabled, the action bar scrolls out of the field of view, along with the nested scrollable content of the child view. The action bar must be in overlay mode to hide scrolling content. When the screen is partially scrolled, the action bar is hidden. Calling to show will cause it to go back to full view. I think you can try it with your own codes.



0


source


Please follow the steps below to solve your problem.

-> Import this package

import android.annotation.SuppressLint;

-> Place this line in above onCreate () method

@SuppressLint ("NewApi")

-> put this line in onCreate () method

getActionBar () hide () ;.

-1


source







All Articles