I had to do this myself, in order to display an "I Agree" button once the user has scrolled to the bottom of a EULA. Lawyers, huh?
In fact when you override the WebView (rather than the ScrollView as in the answer from @JackTurky) you can call computeVerticalScrollRange() to get the height of the content, rather than getBottom() which returns the visible bottom and is not useful.
This is my comprehensive solution. As far as I can see this is all API Level 1 stuff, so it should work anywhere.
public class EulaWebView extends WebView {
public EulaWebView(Context context)
{
this(context, null);
}
public EulaWebView(Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}
public EulaWebView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
public OnBottomReachedListener mOnBottomReachedListener = null;
private int mMinDistance = 0;
/**
* Set the listener which will be called when the WebView is scrolled to within some
* margin of the bottom.
* @param bottomReachedListener
* @param allowedDifference
*/
public void setOnBottomReachedListener(OnBottomReachedListener bottomReachedListener, int allowedDifference ) {
mOnBottomReachedListener = bottomReachedListener;
mMinDistance = allowedDifference;
}
/**
* Implement this interface if you want to be notified when the WebView has scrolled to the bottom.
*/
public interface OnBottomReachedListener {
void onBottomReached(View v);
}
@Override
protected void onScrollChanged(int left, int top, int oldLeft, int oldTop) {
if ( mOnBottomReachedListener != null ) {
if ( (computeVerticalScrollRange() - (top + getHeight())) <= mMinDistance )
mOnBottomReachedListener.onBottomReached(this);
}
super.onScrollChanged(left, top, oldLeft, oldTop);
}
}
I use this to display an "I Agree" button once the user has scrolled to the bottom of the WebView, where I call it like this (in a class which "implements OnBottomReachedListener":
EulaWebView mEulaContent;
Button mEulaAgreed;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eula);
mEulaContent = (EulaWebView) findViewById(R.id.eula_content);
StaticHelpers.loadWebView(this, mEulaContent, R.raw.stylesheet, StaticHelpers.readRawTextFile(this, R.raw.eula), null);
mEulaContent.setVerticalScrollBarEnabled(true);
mEulaContent.setOnBottomReachedListener(this, 50);
mEulaAgreed = (Button) findViewById(R.id.eula_agreed);
mEulaAgreed.setOnClickListener(this);
mEulaAgreed.setVisibility(View.GONE);
}
@Override
public void onBottomReached(View v) {
mEulaAgreed.setVisibility(View.VISIBLE);
}
So when the bottom is reached (or in this case, when they get within 50 pixels of it) the "I Agree" button appears.
StaticHelpers
has been declared? – Macdougall