第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

WebView添加橫向進(jìn)度條

標(biāo)簽:
Android

通常我们在写WebView时,会遇到需要自定义进度条样式位置的问题,下面我们参照系统的实现方案写一个例子

注:实际效果可以参看微信的web页面顶部进度条,当然颜色就别参看了

 

本质就是通过对Web控件addView添加Progress对象,使用WebChromeClient对WebView 页面进度进行监听



自定义的DrawableId,我们参照系统的实现的方法写一个自己的



[代码]xml代码:

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">  

 

    <item android:id="@android:id/background">   //这个属性是指定progress的背景

        <shape>

            <corners android:radius="5dip" />

            <gradient

                android:startColor="#00000000"

                android:centerColor="#00000000"

                android:centerY="0.75"

                android:endColor="#00000000"

                android:angle="270"

                />

        </shape>

    </item>

 

 

    <item android:id="@android:id/progress">   //这个属性是指定progress的进度

        <clip>

            <shape>

                <corners android:radius="5dip" />

                 <gradient

                    android:startColor="#f69988"

                    android:centerColor="#e84e40"

                    android:centerY="0.75"

                    android:endColor="#dd191d"

                    android:angle="0"

                    />

            </shape>

        </clip>

    </item>

 

</layer-list>

 

实际还有一个secondProgress的属性,这个也随意设置,一般用不到

 

看一下addView添加Progress的实现:

[代码]java代码:

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

Drawable drawable =   context.getResources().getDrawable(DrawableId);//该资源以系统原码为参照搞一个自己想要的角度颜色背景

if (progressbar == null)

    progressbar = new ProgressBar(context, null,   android.R.attr.progressBarStyleHorizontal);//这里必须要使用系统的attr属性才能正常实例化出来

RelativeLayout.LayoutParams layoutParams   = new RelativeLayout.LayoutParams

        (ViewGroup.LayoutParams.MATCH_PARENT,   height);//用相对布局更方便指挥这个progress;代码实现的height都为pix级别

layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);//相对于添加它的父类View,顶部

 

if (progressbar != null) {

    progressbar.setLayoutParams(layoutParams);

    if (drawable != null) {

        progressbar.setProgressDrawable(drawable);

        progressbar.setIndeterminate(false);//此值表明进度是不明确的,我们实际在网页打开过程中并不知道具体进度是多少

    }

}

if (<span style="font-size: 9pt; line-height: 25.2px;">viewGroupParent</span><span   style="font-size: 9pt; line-height: 1.8em;"> == null)</span><br>              return;

viewGroupParent.addView(progressbar);

if (webView == null)

    return;

webView.setWebChromeClient(new WebChromeClient());//给webview提供一个可以监听进度的对象,系统内的WebChromeClient 已经有了这个进度通知方法

下面看我们实现的WebChromeClient

[代码]java代码:

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

public class WebChromeClient   extends android.webkit.WebChromeClient   {

      @Override

      public void onProgressChanged(WebView view, int newProgress) {

 

 

          if (newProgress >= Max) {//临界值是用来改变显示状态

              if (progressbar != null)

                  progressbar.setVisibility(View.GONE);

          }   else {

              final int progress = newProgress;//实际能避免新增对象就避免

              if (progressbar != null && progressbar.getVisibility() !=   View.VISIBLE)

                  progressbar.setVisibility(View.VISIBLE);

              if (weakHandler == null)

                  return;

              handler.post(new Runnable() {//handler的实际意图就是为了避免在非主线程改变UI,如果一定要在子线程改变Ui,记得给子线程一个Looper

                  @Override

                  public void run() {

                      if (progressbar != null) {

                          progressbar.setProgress(progress);

                          progressbar.incrementProgressBy(increase);//平缓增加

                      }

                  }

              });

          }

          super.onProgressChanged(view,   newProgress);

      }

 

  }

完活

 

原文链接:http://www.apkbus.com/blog-35555-60412.html

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫(xiě)下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消