我正在尝试在线性布局中设置 webview。我刚刚在线性布局内创建了一个 xml 线性布局文件、进度条和一个 webview。
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ProgressBar
android:id="@+id/progWeb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:max="100"
android:visibility="invisible" />
<WebView
android:id="@+id/web"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
和java文件它只显示进度条。此代码未显示 Webview
public class MainActivity extends Activity {
private WebView web;
private ProgressBar progBar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
web = (WebView) findViewById(R.id.web);
progBar = (ProgressBar) findViewById(R.id.progWeb);
progBar.setVisibility(ProgressBar.INVISIBLE);
String url = "http://www.google.com.pk/";
web.getSettings().setJavaScriptEnabled(true);
web.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
System.out.println(progress);
progBar.setProgress(progress);
if (progress == 100) {
progBar.setVisibility(ProgressBar.INVISIBLE);
progBar.setProgress(0);
} else {
progBar.setVisibility(ProgressBar.VISIBLE);
}
}
});
web.loadUrl(url);
}
}