I have added a webview inside a dialog. I want to enable the dialog positive button when the user has scrolled the webview to the bottom, so that I can assume that the user has read the user agreement.
Asked
Active
Viewed 1,043 times
1
-
show ur xml flie – Gayathri Jul 19 '19 at 07:32
2 Answers
0
You can solve it via Javascript. In the webpage, add the JS code to detect if the user has scrolled to the bottom like this (credits to this post )
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
Android.onUserScrolledToBottom()
}
});
Then in your Android app, create a Javascript Interface class
class MyJavascriptInterface {
TermsAndCondActivity termsAndCondActivity;
MyJavascriptInterface(TermsAndCondActivity termsAndCondActivity) {
this.termsAndCondActivity = termsAndCondActivity;
}
@JavascriptInterface
public void onUserScrolledToBottom() {
termsAndCondActivity.onUserScrolledToBottom();
}
}
Finally in your TermsAndCondActivity, setup the WebView in the onCreate like this
myWebView = view.findViewById(R.id.my_web_view);
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.addJavascriptInterface(new MyJavascriptInterface(this), "Android");
And add the following method
void onUserScrolledToBottom() {
button.setEnabled(true);
}
As an example I've used an activity since you didn't specify the dialog's code, but you should be able to adapt the code easily.

Kazikal
- 156
- 7
0
Thanks for your answers. I have achieved this using onScrollChange() method.
webView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View view, int i, int i1, int i2, int i3) {
if(i1>=webView.getContentHeight()){
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setVisibility(View.VISIBLE);
}else {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setVisibility(GONE);
}
}
});

saranga pani sarma
- 19
- 8