我正在制作一个使用滑动菜单片段的webview浏览器。当我打开这个片段时,应用程序崩溃了。我是碎片的新手,所以如果这很不好我就道歉。如果还有什么我可以帮忙解决这个问题,那就问一下。
下面是片段类
public class WhatsHotFragment extends Fragment {
public WhatsHotFragment(){}
WebView WebViewB;
ProgressBar Pbar6;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_whats_hot, container, false);
Pbar6 = (ProgressBar) getView().findViewById(R.id.progBar6);
WebViewB = (WebView) getView().findViewById(R.id.wvBrowserAesir);
WebSettings webSettings = WebViewB.getSettings();
webSettings.setJavaScriptEnabled(true);
WebViewB.getSettings().setLoadWithOverviewMode(true);
WebViewB.getSettings().setUseWideViewPort(true);
WebViewB.getSettings().setBuiltInZoomControls(true);
WebViewB.getSettings().setAllowFileAccess(true);
WebViewB.setWebViewClient(new InsideWebViewClient());
WebViewB.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
if(progress < 100 && Pbar6.getVisibility() == ProgressBar.VISIBLE){
Pbar6.setVisibility(ProgressBar.VISIBLE);
}
Pbar6.setProgress(progress);
if(progress == 100) {
Pbar6.setVisibility(ProgressBar.VISIBLE);
}
}
});
{
WebViewB.loadUrl("http://www.google.com");
}
return rootView;
}
}
提前致谢!
答案 0 :(得分:2)
更改为
Pbar6 = (ProgressBar) rootView.findViewById(R.id.progBar6);
WebViewB = (WebView) rootView.findViewById(R.id.wvBrowserAesir);
您还可以使用getView().findViewById
中的onActivityCreated
初始化您的观看次数。