[Android]强制系统横屏
来源:互联网 发布:十年前流行的网络歌曲 编辑:程序博客网 时间:2024/05/17 06:01
该实现适用于强制整个手机所有APP及主页显示运行于横屏模式。
原文来自于StackOverflow:http://stackoverflow.com/questions/14587085/how-can-i-globally-force-screen-orientation-in-android
系统权限:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/><uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
1)Service中实现:
orientationChanger = new LinearLayout(this);// Using TYPE_SYSTEM_OVERLAY is crucial to make your window appear on top// You'll need the permission android.permission.SYSTEM_ALERT_WINDOWWindowManager.LayoutParams orientationLayout = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, 0, PixelFormat.RGBA_8888);// Use whatever constant you need for your desired rotationorientationLayout.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR;WindowManager wm = (WindowManager) this.getSystemService(Service.WINDOW_SERVICE);wm.addView(orientationChanger, orientationLayout);orientationChanger.setVisibility(View.VISIBLE);
2)Activity中实现:
wm = (WindowManager) content.getSystemService(Service.WINDOW_SERVICE); orientationChanger = new LinearLayout(content); orientationChanger.setClickable(false); orientationChanger.setFocusable(false); orientationChanger.setFocusableInTouchMode(false); orientationChanger.setLongClickable(false); orientationLayout = new WindowManager.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, windowType, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.RGBA_8888); wm.addView(orientationChanger, orientationLayout); orientationChanger.setVisibility(View.GONE); orientationLayout.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; wm.updateViewLayout(orientationChanger, orientationLayout); orientationChanger.setVisibility(View.VISIBLE);
0 0
- [Android]强制系统横屏
- Android 强制横屏
- android 强制横屏
- Android 强制横屏
- 系统强制横屏、竖屏
- Android Launcher3 强制横屏
- android全屏,强制竖屏,强制横屏
- Android开发之强制横屏和强制竖屏
- android 强制横屏的方法
- android 强制横屏的方法
- Android 程序中设置强制横屏
- 将android 应用强制横屏
- Android 拍照强制横屏解决...
- Qt5.8开发Android:强制横屏
- Android 强制横竖屏
- Android强制横竖屏
- Android 系统 强制 禁用 距离传感器 方法
- Android开发中如何强制横屏和强制竖屏设置
- 【Linux】用户不在sudoers文件中
- 2015-04-09记录--感想
- 如何成为一个C++高级程序员
- ContextImplAndroid应用程序窗口(Activity)的运行上下文环境(Context)的创建过程分析
- 教师资格证的罚则
- [Android]强制系统横屏
- Jdom解析xml
- CentOs网络重启问题:Bringing up interface eth0: Device eth0 does not seem to be presen
- 教师资格证的罚则
- Linux下利用backtrace追踪函数调用堆栈以及定位段错误
- 第五周 项目二--对象作为数据成员
- hdu 2203 亲和串
- [OpenCV] -- win7下配置OpenCV的Qt开发环境
- 教师资格证办理职业前景的