如何使应用程序忽略屏幕方向变化? [英] How to make an application ignore screen orientation change?

查看:89
本文介绍了如何使应用程序忽略屏幕方向变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以使应用程序完全忽略屏幕方向变化?

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.

  1. 在属性内,您需要更改两个字段: 屏幕方向:根据需要选择纵向或横向.这将是默认布局.

  1. 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.

修改活动"实施

现在,您需要在所需的Activity中覆盖单个功能.

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);
}

这是使用Source->Override/Implement Methods时的默认实现 菜单选项.

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)

这篇关于如何使应用程序忽略屏幕方向变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆