大佬教程收集整理的这篇文章主要介绍了Android:滚动完成webview后,可以看到一个按钮,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个webview,显示一个HTML文件.当用户在webview中滚动到此文件的底部时,我想要一个先前隐藏的按钮显示,然后用户可以按此按钮执行某些活动
我在iOS中做了类似的事情,我只是将委托设置为ViewController,只是将按钮设置为可见.我如何在Android上做类似的事情?我注意到iOS中没有回调方法.
编辑:现在,我有一个包含2个对象的活动:包含我的文本的webview和一个当前不可见的按钮.我希望我的活动在webview文本滚动到底部时收到一条消息,并使按钮可见
事实上,当你覆盖WebView(而不是像@JackTurky的答案中的ScrollView)时,你可以调用getContentHeight()来获取内容的高度,而不是getBottom(),它返回可见的底部并且没用.
这是我全面的解决方案.据我所知,这是所有API级别1的东西,因此它应该可以在任何地方使用.
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,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 ( (getContentHeight() - (top + getHeight())) <= mmindistance="" )="" monbottomreachedlistener.onbottomreached(this);="" }="" super.onscrollchanged(left,top,oldleft,oldtop);="" }="" }="">=>
一旦用户滚动到WebView的底部,我用它来显示“我同意”按钮,我在这里调用它(在“实现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);
}
以上是大佬教程为你收集整理的Android:滚动完成webview后,可以看到一个按钮全部内容,希望文章能够帮你解决Android:滚动完成webview后,可以看到一个按钮所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。