<legend id='0nhKM'><style id='0nhKM'><dir id='0nhKM'><q id='0nhKM'></q></dir></style></legend>

<i id='0nhKM'><tr id='0nhKM'><dt id='0nhKM'><q id='0nhKM'><span id='0nhKM'><b id='0nhKM'><form id='0nhKM'><ins id='0nhKM'></ins><ul id='0nhKM'></ul><sub id='0nhKM'></sub></form><legend id='0nhKM'></legend><bdo id='0nhKM'><pre id='0nhKM'><center id='0nhKM'></center></pre></bdo></b><th id='0nhKM'></th></span></q></dt></tr></i><div id='0nhKM'><tfoot id='0nhKM'></tfoot><dl id='0nhKM'><fieldset id='0nhKM'></fieldset></dl></div>

<small id='0nhKM'></small><noframes id='0nhKM'>

  • <tfoot id='0nhKM'></tfoot>

        <bdo id='0nhKM'></bdo><ul id='0nhKM'></ul>
      1. Android:一旦 webview 完成滚动,就使按钮可见

        时间:2023-09-12
      2. <i id='ZYHs6'><tr id='ZYHs6'><dt id='ZYHs6'><q id='ZYHs6'><span id='ZYHs6'><b id='ZYHs6'><form id='ZYHs6'><ins id='ZYHs6'></ins><ul id='ZYHs6'></ul><sub id='ZYHs6'></sub></form><legend id='ZYHs6'></legend><bdo id='ZYHs6'><pre id='ZYHs6'><center id='ZYHs6'></center></pre></bdo></b><th id='ZYHs6'></th></span></q></dt></tr></i><div id='ZYHs6'><tfoot id='ZYHs6'></tfoot><dl id='ZYHs6'><fieldset id='ZYHs6'></fieldset></dl></div>
        <legend id='ZYHs6'><style id='ZYHs6'><dir id='ZYHs6'><q id='ZYHs6'></q></dir></style></legend>
        <tfoot id='ZYHs6'></tfoot>
        • <bdo id='ZYHs6'></bdo><ul id='ZYHs6'></ul>

            1. <small id='ZYHs6'></small><noframes id='ZYHs6'>

                    <tbody id='ZYHs6'></tbody>

                1. 本文介绍了Android:一旦 webview 完成滚动,就使按钮可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个显示 html 文件的 webview.当用户在 webview 中滚动到该文件的底部时,我希望显示一个以前隐藏的按钮,然后用户可以按下该按钮来执行一些活动

                  I have a webview which shows an html file. When the user scrolls to the bottom of this file in webview, I want a button that was previously hidden to show up, which the user can then press to do some activity

                  我在 iOS 中做了类似的事情,我只是将委托设置为 ViewController 并将按钮设置为可见.我如何在 Android 上做类似的事情?我注意到没有像 iOS 那样的回调方法.

                  I did something similar in iOS, where I just set the delegate to the ViewController and just set the button as visible. How do I do something similar on Android? I noticed there isn't a callback method like in iOS.

                  现在,我有一个包含 2 个对象的活动:一个包含我的文本的 web 视图和一个当前不可见的按钮.我希望我的活动在 webview 文本滚动到底部时收到一条消息,并使按钮可见

                  Right now, I have an activity with 2 objects: a webview containing my text, and a button which is currently invisible. I want my activity to receive a message when the webview text scrolls to the bottom, and make the button visible

                  推荐答案

                  为了在用户滚动到 EULA 底部后显示我同意"按钮,我必须自己执行此操作.律师,嗯?

                  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?

                  事实上,当您覆盖 WebView(而不是 @JackTurky 的答案中的 ScrollView)时,您可以调用 computeVerticalScrollRange() 来获取内容的高度,而不是 getBottom() 返回可见底部而不是有用.

                  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.

                  这是我的综合解决方案.据我所知,这都是 API Level 1 的东西,所以它应该可以在任何地方工作.

                  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);
                      }
                  
                  }
                  

                  一旦用户滚动到 WebView 的底部,我就使用它来显示我同意"按钮,我在这里这样称呼它(在实现 OnBottomReachedListener"的类中:

                  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);
                  }
                  

                  所以当到达底部时(或者在这种情况下,当他们到达底部 50 像素以内时)我同意"按钮就会出现.

                  So when the bottom is reached (or in this case, when they get within 50 pixels of it) the "I Agree" button appears.

                  这篇关于Android:一旦 webview 完成滚动,就使按钮可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在“更多"中没有调用 didSelectViewController部分 下一篇:在 Objective-C 中实现委托模式

                  相关文章

                  <i id='QHfFl'><tr id='QHfFl'><dt id='QHfFl'><q id='QHfFl'><span id='QHfFl'><b id='QHfFl'><form id='QHfFl'><ins id='QHfFl'></ins><ul id='QHfFl'></ul><sub id='QHfFl'></sub></form><legend id='QHfFl'></legend><bdo id='QHfFl'><pre id='QHfFl'><center id='QHfFl'></center></pre></bdo></b><th id='QHfFl'></th></span></q></dt></tr></i><div id='QHfFl'><tfoot id='QHfFl'></tfoot><dl id='QHfFl'><fieldset id='QHfFl'></fieldset></dl></div>
                      <bdo id='QHfFl'></bdo><ul id='QHfFl'></ul>

                    <small id='QHfFl'></small><noframes id='QHfFl'>

                  1. <legend id='QHfFl'><style id='QHfFl'><dir id='QHfFl'><q id='QHfFl'></q></dir></style></legend>
                    <tfoot id='QHfFl'></tfoot>