亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android中實(shí)現(xiàn)Webview頂部帶進(jìn)度條的方法

 更新時(shí)間:2015年01月17日 11:24:19   投稿:junjie  
這篇文章主要介紹了Android中實(shí)現(xiàn)Webview頂部帶進(jìn)度條的方法,當(dāng)前很流行的一個(gè)效果,就是打開網(wǎng)頁時(shí)會(huì)在頂部顯示一個(gè)打開進(jìn)度條,需要的朋友可以參考下

寫這篇文章,做份備忘,簡(jiǎn)單滴展示一個(gè)帶進(jìn)度條的Webview示例,進(jìn)度條位于Webview上面.

示例圖如下:

主Activity代碼:

復(fù)制代碼 代碼如下:

package com.droidyue.demo.webviewprogressbar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;

import com.droidyue.demo.webviewprogressbar.R;

public class MainActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      final ProgressBar bar = (ProgressBar)findViewById(R.id.myProgressBar);

      final WebView webView = (WebView)findViewById(R.id.myWebView);
      webView.setWebChromeClient(new WebChromeClient() {

          @Override
          public void onProgressChanged(WebView view, int newProgress) {
              if (newProgress == 100) {
                  bar.setVisibility(View.INVISIBLE);
              } else {
                  if (View.INVISIBLE == bar.getVisibility()) {
                      bar.setVisibility(View.VISIBLE);
                  }
                  bar.setProgress(newProgress);
              }
              super.onProgressChanged(view, newProgress);
          }
         
      });
     
      findViewById(R.id.myButton).setOnClickListener(new OnClickListener() {

          @Override
          public void onClick(View arg0) {
              webView.reload();
          }
         
      });
      final String url = "http://jb51.net";
      webView.loadUrl(url);
  }
 

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }

}

布局文件代碼

復(fù)制代碼 代碼如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
 
    <Button
        android:id="@+id/myButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Reload"
        />

    <ProgressBar
      style="?android:attr/progressBarStyleHorizontal"
        android:id="@+id/myProgressBar"
        android:layout_below="@id/myButton"
        android:layout_width="match_parent"
        android:layout_height="5px"
        />
  <WebView
      android:id="@+id/myWebView"
      android:layout_below="@id/myProgressBar"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      />
</RelativeLayout>

不要忘記在Mainfest加入使用網(wǎng)絡(luò)權(quán)限喲.

復(fù)制代碼 代碼如下:

<uses-permission android:name="android.permission.INTERNET"/>

實(shí)現(xiàn)很簡(jiǎn)單,沒什么技術(shù)含量.備忘而已.

關(guān)于如何自定義進(jìn)度條請(qǐng)參考:http://chabaoo.cn/article/59978.htm

相關(guān)文章

最新評(píng)論