-2

I'm working on an app now I want to lock all the layouts for entire app .. setting orientation for all the layouts is not possible because i'm having at least 50 to 60 layouts. Is there any way to set orientation for entire app please help.. thank you

ManishNegi
  • 569
  • 1
  • 6
  • 19

2 Answers2

5

You just want to set android:screenOrientation="portrait"

 <activity
  android:name=".YourActivity"
  android:screenOrientation="portrait"
  android:theme="@style/theme"></activity>

to your all activity in manifest.xml

M D
  • 47,665
  • 9
  • 93
  • 114
  • 1
    thanx for the response but i'm having many fragments too.. do I need to set it one by one – ManishNegi Nov 18 '15 at 07:23
  • @ManishNegi `Fragment` has no orientation. It's just attach to your `Activity` and if you change orientation your attach fragment all changes. – M D Nov 18 '15 at 07:24
2

You can create a base activity and fix the orientation in it. The rest of your Activity will inherit the same activity.
For example, your Base Activity can be like this.

public class AppNameBaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

}

Now you can make all your activities extend from the AppNameBaseActivity to have a fixed portrait orientation.

Adinia
  • 3,722
  • 5
  • 40
  • 58
Sanjeet A
  • 5,171
  • 3
  • 23
  • 40