My Webview Reloads When I Change From Portrait To Landscape

后端 未结 7 908
刺人心
刺人心 2021-01-01 17:25

I have a simple WebView that runs a web application on an Android. The problem is when I rotate the phone to change it to landscape the webview rel

相关标签:
7条回答
  • 2021-01-01 18:04

    The problem with the above solution is that it renders the screen white for some time before the webview redraws the contents.

    Try using android:configChanges="orientation|keyboardHidden" inside your AndroidManifest.xml file for the activity that displays the webview. That should help.

    0 讨论(0)
  • 2021-01-01 18:10

    Add the following to your AndroidManifest:

    android:configChanges="orientation|keyboard|keyboardHidden"
    

    So it should look something like this:

    <activity android:name=".MyActivity" 
              android:label="@string/app_name" 
              android:configChanges="orientation|keyboard|keyboardHidden">
    

    Obviously, if your WebView needs keyboard support then don't include the keyboard options.

    0 讨论(0)
  • 2021-01-01 18:11

    This can be resolved by overriding onSaveInstanceState(Bundle outState) in your activity and calling saveState from the Webview:

    This blog post may be of help to you.

    0 讨论(0)
  • 2021-01-01 18:13

    Add in Activity

    android:configChanges="keyboardHidden|orientation"
    
    0 讨论(0)
  • 2021-01-01 18:14

    Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare

    <activity android:configChanges="orientation|screenSize">
    

    Here's the docs: http://developer.android.com/guide/topics/resources/runtime-changes.html

    0 讨论(0)
  • 2021-01-01 18:17
    @Override
    public void onConfigurationChanged(Configuration newConfig){
        super.onConfigurationChanged(newConfig);
    } 
    

    Add above method in your activity.. and

    android:configChanges="keyboard|keyboardHidden|orientation"

    in your manifest file

    0 讨论(0)
提交回复
热议问题