我写的android服务改变了整个设备的方向
所以主页的方向改变了
这是代码
WindowManager wm = (WindowManager) getSystemService(Service.WINDOW_SERVICE);
LinearLayout orientationChanger = new LinearLayout(this);
orientationChanger.setClickable(false);
orientationChanger.setFocusable(false);
orientationChanger.setFocusableInTouchMode(false);
orientationChanger.setLongClickable(false);
LayoutParams orientationLayout = new WindowManager.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.RGBA_8888);
wm.addView(orientationChanger, orientationLayout);
orientationChanger.setVisibility(View.GONE);
orientationLayout.screenOrientation = x;
wm.updateViewLayout(orientationChanger, orientationLayout);
orientationChanger.setVisibility(View.VISIBLE);</i>我希望我的服务更改方向,而不是主页和应用程序页面
或者如何编写返回到默认设备方向的其他代码
发布于 2014-03-19 00:30:24
你可以只使用下面的代码:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);或setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
要更改方向,请在每个要更改的活动中运行其中一个。
https://stackoverflow.com/questions/22485326
复制相似问题