android - Hiding/Showing the action bar when scrolling -
i'm using observablerecyclerview in fragment (i'm using fragments because have tabs in app). need action bar hidden/shown based on scroll of observablerecyclerview. followed answer in question, bit misleading since couldn't understand oldscrolly is.
i tried code hiding/showing bar without animation
@override public void onuporcancelmotionevent(scrollstate scrollstate) { actionbar ab = ((appcompatactivity) getactivity()).getsupportactionbar(); if (scrollstate == scrollstate.up) { if (ab.isshowing()) { ab.hide(); } } else if (scrollstate == scrollstate.down) { if (!ab.isshowing()) { ab.show(); } } } edit:
activity_main.xml
<android.support.design.widget.coordinatorlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/coordinator_layout_all" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivity"> <linearlayout android:id="@+id/toolbarcontainer" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.toolbar android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/primary" android:elevation="2dp" android:minheight="?attr/actionbarsize" app:theme="@style/themeoverlay.appcompat.dark.actionbar" /> <jo.edu.gju.motassem.seniorproject.slidingtablayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/primary" android:elevation="2dp" /> <android.support.v4.view.viewpager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" /> </linearlayout> <android.support.design.widget.floatingactionbutton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentright="true" android:layout_gravity="end|bottom" android:layout_marginbottom="16dp" android:layout_marginright="16dp" android:src="@drawable/ic_add_white" app:backgroundtint="@color/accent" app:borderwidth="0dp" app:elevation="6dp" app:fabsize="normal" app:ripplecolor="@color/primary" /> </android.support.design.widget.coordinatorlayout> fragment.xml
<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <progressbar android:id="@+id/progress_bar" style="?android:progressbarstyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" /> <com.github.ksoichiro.android.observablescrollview.observablerecyclerview android:id="@+id/rv" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" /> </framelayout>
you can use coordinatorlayout in .xml file contain toolbar , see below code:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/all" android:layout_height="match_parent" android:layout_width="wrap_content" android:orientation="vertical" android:fitssystemwindows="true"> <android.support.design.widget.coordinatorlayout android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollflags="scroll|enteralways" > <android.support.design.widget.appbarlayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_height="?attr/actionbarsize" android:layout_width="match_parent" app:layout_scrollflags="scroll|enteralways" app:layout_collapsemode="pin" /> </android.support.design.widget.appbarlayout> <framelayout android:id="@+id/content_layout" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior" > </framelayout> </android.support.design.widget.coordinatorlayout> </linearlayout>
Comments
Post a Comment