खैर मैं CustomWebView
और GestureDetector
से लागू कर दिया है:
CustomWebView.java:
public class CustomWebView extends WebView {
private GestureDetector gestureDetector;
public CustomWebView(Context context) {
super(context);
}
public CustomWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
return gestureDetector.onTouchEvent(ev) || super.onTouchEvent(ev);
}
public void setGestureDetector(GestureDetector gestureDetector) {
this.gestureDetector = gestureDetector;
}
}
web_fragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical">
<com.customview.CustomWebView
android:id="@+id/customWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true" />
</LinearLayout>
CustomeGestureDetector इशारा जांच के लिए CLSS (मैं टुकड़ा में शामिल किया है):
private class CustomeGestureDetector extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if(e1 == null || e2 == null) return false;
if(e1.getPointerCount() > 1 || e2.getPointerCount() > 1) return false;
else {
try {
if(e1.getY() - e2.getY() > 20) {
// Hide Actionbar
getSupportActionBar().hide();
customWebView.invalidate();
return false;
}
else if (e2.getY() - e1.getY() > 20) {
// Show Actionbar
getSupportActionBar().show();
customWebView.invalidate();
return false;
}
} catch (Exception e) {
customWebView.invalidate();
}
return false;
}
}
}
WebFragment.java:
private CustomWebView customWebView;
customWebView= (CustomWebView) view.findViewById(R.id.customWebView);
customWebView.setGestureDetector(new GestureDetector(new CustomeGestureDetector()));
यह मेरे लिए ठीक काम करता है, आशा है कि यह आप में मदद मिलेगी।
स्रोत
2016-03-18 06:13:05
उदाहरण ([यहां] है http://www.techrepublic.com/article/pro-tip- अधिकतम-एंड्रॉइड-स्क्रीन-रीयल-एस्टेट-बाय-शोइंग-एंड-हाइडिंग-द-एक्शन-बार /) –
यह उदाहरण रैखिक लेआउट के लिए दिखाता है। वेबव्यू – Sathish
में इसे कैसे कार्यान्वित करें यहां एक उदाहरण है [http://stackoverflow.com/questions/14752523/how-to-make-a-scroll-listener-for-webview-in-android/14753235#14753235] –