title: Android Hide ActionBar while scrolling in a ListView
body: <p>I am looking for a method to hide actionbar like GooglePlay, when scrolling down and let the ActionBar reappear when scrolling up. I have found a lot of guides but them are about <strong>recyclerview</strong> and I am using <strong>listview</strong>. </p>
  
  <p>The best guide I found is this: <a href="https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling%28part3%29/" rel="nofollow noreferrer">https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling%28part3%29/</a>.</p>
  
  <p>This is my layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/coordinatorLayout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  
  &lt;ListView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/FList" /&gt;
  
  &lt;android.support.design.widget.AppBarLayout
      android:id="@+id/appBarLayout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;android.support.v7.widget.Toolbar
          android:id="@+id/toolbar"
          android:layout_width="match_parent"
          android:layout_height="?attr/actionBarSize"
          android:background="?attr/colorPrimary"/&gt;
  
  &lt;/android.support.design.widget.AppBarLayout&gt;
  
  &lt;android.support.v4.view.ViewPager
      android:id="@+id/viewPager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/&gt;
  
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>This is my error:</p>
  
  <pre><code>Process: com.mycompany.test, PID: 6172
          java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mycompany.test/com.mycompany.test.activities.Friends_List_Activity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2329)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
                  at android.app.ActivityThread.access$900(ActivityThread.java:147)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:135)
                  at android.app.ActivityThread.main(ActivityThread.java:5254)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:372)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
                  at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)
           Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
                  at android.view.LayoutInflater.createView(LayoutInflater.java:633)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
                  at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
                  at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:684)
                  at android.view.LayoutInflater.inflate(Unknown Source)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
                  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:428)
                  at android.app.Activity.setContentView(Activity.java:2144)
                  at com.mycompany.test.activities.Friends_List_Activity.onCreate(Friends_List_Activity.java:26)
                  at android.app.Activity.performCreate(Activity.java:5933)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
                  at android.app.ActivityThread.access$900(ActivityThread.java:147)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:135)
                  at android.app.ActivityThread.main(ActivityThread.java:5254)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:372)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
                  at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)
  </code></pre>
  
  <p><strong>EDIT:</strong>
  <a href="https://stackoverflow.com/questions/13559275/hiding-the-actionbar-on-recyclerview-listview-onscroll/17767691#17767691">Hiding the ActionBar on RecyclerView/ListView onScroll</a> 
  In the guide above I can't use the code, I need to extend Activity so I am unable to use getSupportActionBar()</p>
  
  <p><strong>EDIT 2.0</strong>:</p>
  
  <p>My activity:</p>
  
  <pre><code>public class Contacts_List_Activity extends Activity {
      private SearchView mSearchView;
      private Contacts_List_Adapter_OBJ ContactsAdapter;
      private Menu menu;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_Contacts_list);
  
          ContactsAdapter = new Contacts_List_Adapter_OBJ(this);
          final ListView listView = (ListView) findViewById(R.id.Contacts);
          listView.setAdapter(ContactsAdapter);
      }
  
      @Override
      public boolean onCreateOptionsMenu(final Menu menu) {
          this.menu = menu;
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.menu_Contact_list_screen, menu);
  
          mSearchView = (SearchView) menu.findItem(R.id.search).getActionView();
  
          mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
  
              @Override
              public boolean onQueryTextSubmit(String s) {
                  return false;
              }
  
              @Override
              public boolean onQueryTextChange(String s) {
  
                  Contacts_List_Adapter_OBJ FilterAdapter = ContactsAdapter;
                  if (TextUtils.isEmpty(s)) {
                      FilterAdapter.getFilter().filter("");
                  } else {
                      FilterAdapter.getFilter().filter(s.toLowerCase());
                  }
                  return true;
              }
          });
          mSearchView.setOnSearchClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Set_MenuItem_Visible(false);
              }
          });
          mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {
              @Override
              public boolean onClose() {
                  Set_MenuItem_Visible(true);
                  return false;
              }
          });
  
          final MenuItem searchMI = menu.findItem(R.id.search);
  
          mSearchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
              @Override
              public void onFocusChange(View view, boolean queryTextFocused) {
                  if (!queryTextFocused) {
                      searchMI.collapseActionView();
                  }
              }
          });
          return true;
      }
  
  }
  </code></pre>