我一直在试图把一个后退按钮进度条在一个web视图并继续使用了Android默认的Web浏览器中我的应用程序的URL负载来代替。
如果我设法保持到浏览应用程序内,并保持后退按钮,进度条一直没有出现,如果我设法得到进度条显示了code在底部shouldoverideurl拿出从未读过和默认的浏览器启动,我尝试了所有的谷歌教程和解决方案,但他们没有工作。我目前正在使用谷歌..谁能帮助??
公共类livebrad延伸活动{ 的WebView mWebView; / **第一次创建活动时调用。 * / @覆盖 公共无效的onCreate(包savedInstanceState) { super.onCreate(savedInstanceState); //添加Progrss栏支持 。this.getWindow()requestFeature(Window.FEATURE_PROGRESS); 的setContentView(R.layout.brows); //使进度条可见 。getWindow()setFeatureInt(Window.FEATURE_PROGRESS,Window.PROGRESS_VISIBILITY_ON); //获取Web视图 mWebView =(web视图)findViewById(R.id.webView); //这是你给的ID //在main.xml中的web视图 mWebView.getSettings()setJavaScriptEnabled(真)。 。mWebView.getSettings()setSupportZoom(真正的); //缩放控制对网络(不需要这个 //如果ROM支持多点触控 。mWebView.getSettings()setBuiltInZoomControls(真正的); //如果由ROM支持启用多点触摸 //装载网址 mWebView.loadUrl(www.bbc.co.uk); //设置浏览器客户端,并定义onProgressChanged //这使得进度条进行更新。 最后活动MyActivity =这一点; mWebView.setWebChromeClient(新WebChromeClient(){ 公共无效onProgressChanged(web视图来看,INT进度) { //使加载URL后杠消失,并改变字符串载入中... MyActivity.setTitle(载入中...); MyActivity.setProgress(进度* 100); //使酒吧后消失网址是装 完成加载后//返回应用程序名称 如果(进度== 100) MyActivity.setTitle(R.string.app_name); }类HelloWebViewClient扩展WebViewClient { @覆盖 公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){ view.loadUrl(URL); 返回true; } } }); } //方法的onCreate结束
}
解决方案 进口android.app.Activity; 进口android.app.ProgressDialog; 进口android.os.Bundle; 进口android.webkit.WebView; 进口android.webkit.WebViewClient; 公共类SandbarinFacebook延伸活动{ 的WebView mWebView; 保护无效的onCreate(包savedInstanceState){ super.onCreate(savedInstanceState); 的setContentView(R.layout.fb); 最后ProgressDialog PD = ProgressDialog.show(这一点,,载入中..., 真正); mWebView =(web视图)findViewById(R.id.webkitWebView1); mWebView.getSettings()setJavaScriptEnabled(真)。 。mWebView.getSettings()setSupportZoom(真正的); 。mWebView.getSettings()setBuiltInZoomControls(真正的); mWebView.setWebViewClient(新WebViewClient(){ @覆盖 公共无效onPageFinished(web视图查看,字符串URL){ 如果(pd.isShowing()&安培;&安培;!概率pd =空) { pd.dismiss(); } } }); mWebView.loadUrl(m.facebook/sandbarathens); } }I have been trying to put a back button progress bar in a webview and keep the url loading within my app instead of using the android default web browser.
If I manage to keep to browsing within the app and keep the back button the progress bar never shows up if I manage to get the progress bar to show up the code at the bottom for shouldoverideurl come up never read and the default browser launches, I tried all the google tutorials and solution but none of them work. I am currently using google.. Can anyone help??
public class livebrad extends Activity { WebView mWebView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Adds Progrss bar Support this.getWindow().requestFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.brows); // Makes Progress bar Visible getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); // Get Web view mWebView = (WebView) findViewById( R.id.webView ); //This is the id you gave //to the WebView in the main.xml mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setSupportZoom(true); //Zoom Control on web (You don't need this //if ROM supports Multi-Touch mWebView.getSettings().setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM // Load URL mWebView.loadUrl("www.bbc.co.uk"); // Sets the Chrome Client, and defines the onProgressChanged // This makes the Progress bar be updated. final Activity MyActivity = this; mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { //Make the bar disappear after URL is loaded, and changes string to Loading... MyActivity.setTitle("Loading..."); MyActivity.setProgress(progress * 100); //Make the bar disappear after URL is loaded // Return the app name after finish loading if(progress == 100) MyActivity.setTitle(R.string.app_name); }class HelloWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } }); }//End of Method onCreate}
解决方案 import android.app.Activity; import android.app.ProgressDialog; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; public class SandbarinFacebook extends Activity { WebView mWebView; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fb); final ProgressDialog pd = ProgressDialog.show(this, "", "Loading...", true); mWebView = (WebView) findViewById(R.id.webkitWebView1); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setSupportZoom(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { if(pd.isShowing() && pd!=null) { pd.dismiss(); } } }); mWebView.loadUrl("m.facebook/sandbarathens"); } }
更多推荐
添加进度条的WebView
发布评论