开发者

Disable landscape orientation in Android Browser?

开发者 https://www.devze.com 2023-02-08 16:02 出处:网络
I know there is a way t开发者_如何学Co restrict the orientation within an app, but is there a way in code of a web page (whether it be HTML, CSS or JS) to restrict the web view to only potrait?If you

I know there is a way t开发者_如何学Co restrict the orientation within an app, but is there a way in code of a web page (whether it be HTML, CSS or JS) to restrict the web view to only potrait?


If you are using a Webview inside an Activity you will restrict to portrait adding the property

android:screenOrientation

to your Manifest.xml

 <activity android:name=".MyActivity"
              android:label="Jorge´s Activity"
              android:screenOrientation="portrait">


No, there isn't. That kind of control is on Android's end, not the web page it's displaying.


You can choose to show a message telling the user to turn their phone if the orientation is not right. window.orientation will tell you the orientation of the device. 0 is upright, 90 is landscape.


Try

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
0

精彩评论

暂无评论...
验证码 换一张
取 消