有没有一种方法,使应用程序完全忽略屏幕方向更改?
Is there a way to make an application completely ignore a screen orientation change?
这是可能的,很容易,要覆盖默认行为,并禁止屏幕方向变化时,键盘打开/关闭。
It is possible, quite easily, to override the default behavior and forbid a screen orientation change when the keyboard is open/closed.
修改清单
打开清单,切换到应用程序选项卡,选择您希望重写的方向改变行为所需的活动。
Open the manifest, switch to the Application tab and select the desired Activity you wish to override for the orientation change behavior.
在您需要更改两个字段属性: 屏幕方向:选择纵向或横向 - 无论是需要的。这将是默认布局。
Within Attributes you need to change two fields: Screen orientation: select either portrait or landscape - whichever is desired. This will be the default layout.
有关配置选择的事件改变了你希望覆盖: 在这种情况下,这些是keyboardHidden和取向
Select events for Config changes you wish to override: In this case these are keyboardHidden and orientation.
修改活动实施
现在你需要所需的活动范围内覆盖一个单一的功能。
Now you need to override a single function within desired Activity.
只需添加以下到您的活动的类的功能。
Just add the function below to your Activity's class.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
这是默认的实现,如果使用源 - >覆盖/实现方法
菜单选项。
This is the default implementation if using the Source->Override/Implement Methods
menu option.
这就是它!现在你的方向将始终保持。
That's it! Now your orientation will always be kept.
请记住,这个设置是每个活动 - !所以你需要重复每次要禁止方向变化的活动这一步
Remember that this setting is per Activity - so you need to repeat this step for each Activity you wish to forbid the orientation change!
(基于SDK 1.1)
(Based on SDK 1.1)