我可以在eclipse中控制方向但我现在需要在android studio中更改方向。在eclipse中我找到了android清单文件并从文件中解决了问题。但在android studio中,我只找到manifest.xml文件。
I also saw the link 那么,我该如何解决这个问题呢?
答案 0 :(得分:0)
您不需要在Manifest.xml
文件中声明屏幕方向,您可以在onCreate
Activity
方法中设置屏幕方向程序运行时调用。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
您也可以使用其他方向。这将使整个计划的生命周期中的方向保持一致。
但是,如果在调用OnDestroy
之后希望它返回到另一个设置,只需使用sharedPreferences(https://developer.android.com/reference/android/content/SharedPreferences.html)保存方向设置,然后写一个if else语句来更改之后的值事件
答案 1 :(得分:0)
要控制方向,您必须覆盖清单中的活动属性android:configChanges。 像
x
有关详细信息,请查看此https://developer.android.com/guide/topics/resources/runtime-changes.html