我如何能在全球范围强制屏幕方向Android中? [英] How can I globally force screen orientation in Android?
问题描述
有一个数字,是能够迫使屏幕旋转的应用程序。他们的工作,即使一个应用程序,明确要在另一个方向来看待。现在我禁用加速旋转系统设置,并设置我的preferred方向。一个应用程序仍然可以忽略这一点。
There are a number of apps that are able to force screen rotation. They work even if an app explicitly wants to be viewed in another orientation. Right now I am disabling the accelerometer rotation system setting and setting my preferred orientation. An app can still override this.
下面是能够覆盖一个应用程序的请求的方向的应用程序之一:
Here is one of the apps that is able to override an app's requested orientation:
<一个href="https://play.google.com/store/apps/details?id=nl.fameit.rotate&hl=en">https://play.google.com/store/apps/details?id=nl.fameit.rotate&hl=en
推荐答案
这可以通过创建一个隐藏的系统对话框进行。其样的黑客攻击,但其疯狂到工作。
This can be done by creating a hidden system dialog. Its kind of a hack but its crazy enough to work.
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);
这篇关于我如何能在全球范围强制屏幕方向Android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!