In Chrome, the address bar will be hidden/shown when user swipes up/down the content.
Can I implement the similar logic to my app?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame">
<WebView
android:id="@+id/my_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
I wonder if there is anything I can do by the following code, so that the ActionBar will be hidden/shown when user swipe up/down the webView.
WebView webView = (WebView) findViewById(R.id.my_webview);
webView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch (View v, MotionEvent event) {
webView.onTouchEvent(event);
}
});
First you need layout with alignParentBottom and match_parent WebView and some bar at top:
Then you need code:
1) Declare and set some internal values and resize WebView to make it below our bar:
2) Create resize method. Here we check new height with limits of screen top and bar height
3) Create custom onTouch listener where we will resize WebView and change Y-value of our bar