问题
Im using webview and I want to stop reloading the page when orientation changes.
I have the following in my activity:
@Override
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
}
@Override
protected void onSaveInstanceState(Bundle outState ){
((WebView) findViewById(R.id.webView)).saveState(outState);
}
And in my layout, I have:
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:configChanges="keyboardHidden|orientation"
android:visibility="gone" >
But the above code didn't work. Im testing it in Android 2.3.3.
回答1:
Add android:configChanges="keyboardHidden|orientation" to your activity which was used by this Layout in your AndroidManifest.xml file like this
<activity
android:name=".UserProfileActivity"
android:configChanges="orientation|screenSize|keyboardHidden"/>
User screensize for newly version orientation might not be supported in some version need to use screensize for configChanges
来源:https://stackoverflow.com/questions/15762436/android-webview-handling-orientation-not-working