使用AndroidWebView怎么实现顶部进度条

发布时间:2021-06-02 17:59:43 作者:Leah
来源:亿速云 阅读:178

这篇文章给大家介绍使用AndroidWebView怎么实现顶部进度条,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

布局:

<RelativeLayout  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical">  <WebView   android:id="@+id/webView"   android:layout_width="match_parent"   android:layout_height="match_parent"   android:layout_below="@+id/toolbar_container" />  <ProgressBar   android:id="@+id/progressBar"      android:layout_width="match_parent"   android:layout_height="3dp"   android:layout_below="@+id/toolbar_container"   android:background="@drawable/crowd_progressbar_unselect" /></RelativeLayout>

进度条样式:

<style name="crowd_item_progressBar">  <item name="android:indeterminateOnly">false</item>  <item name="android:progressDrawable">@drawable/crowd_progressbar_background</item>  <item name="android:minHeight">10dp</item>  <item name="android:maxHeight">10dp</item></style>

进度图片:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item  android:id="@android:id/progress" >  <clip>   <shape>    <solid android:color="@color/selected"/>    <!--<corners android:radius="1.5dp"/>-->   </shape>  </clip> </item></layer-list>

代码:

public class WebChromeClient extends android.webkit.WebChromeClient {  @Override  public void onProgressChanged(WebView view, int newProgress) {   if (newProgress == 100) {    mProgressBar.setVisibility(GONE);   } else {    if (mProgressBar.getVisibility() == GONE)     mProgressBar.setVisibility(VISIBLE);    mProgressBar.setProgress(newProgress);   }   super.onProgressChanged(view, newProgress);  } } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) {  LayoutParams lp = (LayoutParams) mProgressBar.getLayoutParams();  lp.x = l;  lp.y = t;  mProgressBar.setLayoutParams(lp);  super.onScrollChanged(l, t, oldl, oldt); }}

关于使用AndroidWebView怎么实现顶部进度条就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

推荐阅读:
  1. js顶部进度条最小插件nanobar.js如何实现
  2. js 实现回到顶部

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android

上一篇:怎么在C++中合并两个有序数组

下一篇:怎么在Java中实现IO流和文件操作

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》