Android Webview Handling Orientation Not Working

时光总嘲笑我的痴心妄想 提交于 2019-12-24 10:48:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!