Lio*_*ior 49
这应该是你的诀窍:
import android.provider.Settings;
public static void setAutoOrientationEnabled(Context context, boolean enabled)
{
Settings.System.putInt( context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, enabled ? 1 : 0);
}
Run Code Online (Sandbox Code Playgroud)
添加AndroidManifest.xml的权限
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
Run Code Online (Sandbox Code Playgroud)
你可以在这里找到文档
始终使用用户指定的屏幕方向,这将应用用户选择的任何方向,并且在禁用屏幕时不会旋转屏幕。
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27590 次 |
| 最近记录: |