0

I can control orientation in eclipse but I need now change orientation in the android studio.In eclipse I find android manifest file and solved the problem from the file.But in android studio, I only find manifest.xml file.

img

I also saw the link So,how can I solve the problem?

Community
  • 1
  • 1

2 Answers2

0

You don't need to declare screen orientation in the Manifest.xml file, you can set the screen's orientation in the onCreate method in your Activity which is called when your program runs.

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

You can use other orientations as well. This will keep the orientation the same throughout the program's lifecycle.

If however, you want it to return to another setting after OnDestroy is called, simply save the orientation setting using sharedPreferences (https://developer.android.com/reference/android/content/SharedPreferences.html) and then write an if else statement to change the value after the event.

Curtis White
  • 250
  • 3
  • 13
0

To control orientation ,you have to override the attribute android:configChanges of activity in manifest. like

`<activity android:name=".MyActivity"
          android:configChanges="orientation|keyboardHidden"
          android:label="@string/app_name">`

for more detail go through this https://developer.android.com/guide/topics/resources/runtime-changes.html

pcrafter
  • 31
  • 3