Search code examples
androidbuttonscreen-rotation

Rotate the Activity with click on a Button


I am using this CODE to disable the auto rotate in my App:

            android:screenOrientation="portrait"

What I want is to write a CODE inside my Activity to make the App on portrait or landscape as the user want by clicking a button and save it in SharedPreferences.

I am already made layout and layout-land with different design but as i disabled it in my Manifest its is not showing up, Cause i want the users chose what they want!

Thanks for any Help

UPDATE

    /** Here is the Rotation Button */
View.OnClickListener mb2 = new View.OnClickListener() {
    public void onClick(View v) {
        startActivity(new Intent(".ABOUT"));
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    }
};

It doesn't work this way!


Solution

  • setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    

    or

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);