在Android的web视图方向改变 [英] Android orientation Change in WebView
问题描述
我使用的关注code停止重新加载网页
I am Using Following Code to stop reloading the web page
public class MainActivity extends Activity {
WebView webView;
@Override
protected void onSaveInstanceState(Bundle outState) {
WebView webView1 = (WebView)findViewById(R.id.webView);
webView1.saveState(outState);
}
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView)findViewById(R.id.webView);
String url="http://www.google.com";
if (savedInstanceState != null)
{
((WebView)findViewById(R.id.webView)).restoreState(savedInstanceState);
}
else{
webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
String name = MainActivity.this.webView.getTitle();
TextView t=(TextView)findViewById(R.id.title);
t.setText(name);
Toast.makeText(getApplicationContext(), name, Toast.LENGTH_SHORT).show();
}
});
final Activity activity = this;
final ProgressDialog progressDialog = new ProgressDialog(activity);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
final ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setUserAgentString("Android");
webView.setWebChromeClient(new WebChromeClient()
{
public void onProgressChanged(WebView view, int progress) {
progressBar.setVisibility(View.VISIBLE);
progressDialog.setProgress(0);
activity.setProgress(progress * 1000);
progressDialog.incrementProgressBy(progress);
if(progress > 75)
progressBar.setVisibility(View.GONE);
}
}
);
webView.loadUrl(url);
}
和使用的android:configChanges =方向|键盘| keyboardHidden
在我的清单文件
但是当我运行它,并改变我的手机的方向。
But when i run it and change orientation of my phone.
页面仍然可以重新加载和进度开始出现,绝不解雇。
The page still get reloaded and progressbar started showing and never dismiss.
谁能告诉我什么是错在这?
can anyone tell me whats wrong in this??
推荐答案
默认情况下,活动是在方向改变重建。但是你可以通过设置更改的android:configChanges =keyboardHidden |方向
在在AndroidManifest.xml您的活动的声明,并覆盖 onConfigurationChanged()
活动类的方法。
By default the activity is recreated at orientation change. But you can change it by setting android:configChanges="keyboardHidden|orientation
in the declaration of your activity in AndroidManifest.xml and overriding the onConfigurationChanged()
method of the activity class.
这篇关于在Android的web视图方向改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!