android - I want to hide Action Bar while scrolling the webview -
basically have bottomnavigationview activity in there 3 fragments (tab1,tab2,tab3) contain 3 webviews, wanna while scrolling down webview actionbar should hide, likegetsupportactionbar().hide();
know there answers in stack overflow same question, don't know in case, because beginner in android development
here activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout 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/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.hackerinside.jaisonjoseph.polysocial.mainactivity"> <framelayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@android:color/holo_blue_dark"> <textview android:id="@+id/message" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginbottom="@dimen/activity_vertical_margin" android:layout_marginleft="@dimen/activity_horizontal_margin" android:layout_marginright="@dimen/activity_horizontal_margin" android:layout_margintop="@dimen/activity_vertical_margin" /> </framelayout> <android.support.design.widget.bottomnavigationview android:id="@+id/navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="?android:attr/windowbackground" android:layout_alignparentbottom="true" app:menu="@menu/navigation" />
this first fragment (fragment_tab1)
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context="com.hackerinside.jaisonjoseph.polysocial.tab1"> <framelayout android:id="@+id/frame1" android:layout_width="match_parent" android:layout_height="3dp" android:background="@android:color/transparent"> <progressbar android:id="@+id/progressbar1" style="?android:attr/progressbarstylehorizontal" android:layout_width="fill_parent" android:layout_height="3dp" android:background="@android:color/transparent" android:foregroundgravity="top" android:progressdrawable="@drawable/custom_progress" android:progress="20"/> </framelayout> <webview android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" > </webview>
this java code tab1
package com.hackerinside.jaisonjoseph.polysocial; import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.motionevent; import android.view.view; import android.view.viewgroup; import android.webkit.webchromeclient; import android.webkit.webview; import android.widget.framelayout; import android.widget.progressbar; /** * simple {@link fragment} subclass. */ public class tab1 extends fragment { public progressbar bar; public framelayout framelayout; public tab1() { // required empty public constructor } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_tab1, null); framelayout=(framelayout) rootview.findviewbyid(r.id.frame1); bar=(progressbar)rootview.findviewbyid(r.id.progressbar1); bar.setmax(100); final webview view=(webview) rootview.findviewbyid(r.id.webview); view.loadurl("http://facebook.com"); view.getsettings().setjavascriptenabled(true); view.setwebviewclient(new mywebviewclient()); view.setwebchromeclient(new webchromeclient(){ public void onprogresschanged(webview view1,int progress){ framelayout.setvisibility(view.visible); bar.setprogress(progress); if (progress==100){ framelayout.setvisibility(view.gone); } super.onprogresschanged(view1,progress); } }); view.getsettings().setbuiltinzoomcontrols(true); view.getsettings().setdisplayzoomcontrols(false); bar.setprogress(0); return rootview; } }
here sample idea of implementation.
boolean isshowing; //oncraete code here webview mscrollview = (webview) findviewbyid(r.id.scrollview); mscrollview.getviewtreeobserver().addonscrollchangedlistener(new viewtreeobserver.onscrollchangedlistener() { @override public void onscrollchanged() { float mfloat = mscrollview.getscrolly(); if (mfloat >= ttoolbar.getheight() && isshowing) { toolbaranimatehide(); } else if (mfloat == 0 && !isshowing) { toolbaranimateshow(0); } } }); private void toolbaranimateshow(final int verticaloffset) { isshowing = true; //ttoolbar view(any view) // add getsupportactionbar().hide() code here hide actionbar // remove below code or comment ttoolbar.animate() .translationy(0) .setinterpolator(new linearinterpolator()) .setduration(180) .setlistener(new animatorlisteneradapter() { @override public void onanimationstart(animator animation) { toolbarsetelevation(verticaloffset == 0 ? 0 : toolbar_elevation); } }); } private void toolbaranimatehide() { isshowing = false; // add getsupportactionbar().show() code here showactionbar // remove below code or comment //ttoolbar view(any view) ttoolbar.animate() .translationy(-ttoolbar.getheight()) .setinterpolator(new linearinterpolator()) .setduration(180) .setlistener(new animatorlisteneradapter() { @override public void onanimationend(animator animation) { toolbarsetelevation(0); } }); }
Comments
Post a Comment