I want to enable orientation when rotating the device. Normally this happens automatically but in this locally sourced webview, it doesn’t happen. It loads in portrait but I would like it to change the orientation depending on how the device is tilted.
I have in the /assets folder adjectives.html
// In Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView wv = new WebView(this);
setContentView(wv);
wv.getSettings().setBuiltInZoomControls(true);
wv.loadUrl("file:///android_asset/adjectives.html");
}
// In manifest
<activity android:name=".WebViewActivity"
android:configChanges="orientation|keyboardHidden">
</activity>
Any ideas?
If you use
android:configChangesthen the specific changes aren’t handled for you automatically and you must handle them yourself.To do this, you must override
onConfigurationChanged(Configuration newConfig)and checknewConfigto see what the newConfigurationis. If the change is related to orientation, you’ll need to set a new content view.The easiest thing would be to remove
orientationfromandroid:configChanges(unless you have a particular reason not to) and put yourWebViewinside a layout XML file and use that for your content view inonCreate(...). This will allow the default ‘automatic’ handling of changes in orientation.