以编程方式在android中锁定方向 [英] orientation lock in android programmatically

查看:60
本文介绍了以编程方式在android中锁定方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码.

Java

public void lockScreenOrientation() {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
}

public void unlockScreenOrientation() {
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}

我正在从 javascript 调用这些函数.控制正在进入这些方法.但是方向没有锁定.

I am calling these functions from javascript. Control is entering these methods. However the orientation is not locked.

我尝试跟随锁定方向

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);

这些似乎都不起作用.任何指针都会有所帮助.

None of these seem to work. Any pointers would be helpful.

推荐答案

Activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);


以任何方向锁定屏幕(活动).

需要 API 级别 >= 18


Locks the screen (activity) in whatever the orientation it was.

Requires API Level >= 18

这篇关于以编程方式在android中锁定方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆