在我的应用控制默认的自动旋转屏幕 [英] Control default auto rotate screen in my application
本文介绍了在我的应用控制默认的自动旋转屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的应用程序切换按钮。我想改变或控制默认设置,自动旋转屏幕(设置>显示>自动旋转屏幕)编程。是否有人知道如何做到这一点?
I have a toggle button in my application. I want to change or control default setting, Auto rotate screen(Settings>Display>Auto rotate screen) programmatically. Does anybody know how to do this?
推荐答案
你有没有在你的活动试过吗?
Have you tried this in your Activity?
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//This is the default value
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
之后,你可以用它来禁用自动定位:
After that you can use this to disable the auto orientation:
public static void setAutoOrientationEnabled(ContentResolver resolver, boolean enabled)
{
Settings.System.putInt(resolver, Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}
<一个href="http://developer.android.com/reference/android/provider/Settings.System.html#ACCELEROMETER_ROTATION">Documentation
这篇关于在我的应用控制默认的自动旋转屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文