-3

Hi I don't want to set activity orientation I want to restrict only dialog. Let me know is it possible.

**

Only for Dialog not Activity

.**

    Dialog d = new Dialog(context);
    Window window = d.getWindow();
    window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
            WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);

    //d.setCancelable(false);
    d.setContentView(R.layout.viewpager_main_for_printing);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(d.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    lp.gravity = Gravity.CENTER;
    lp.screenOrientation=WindowManager.LayoutParams./// Here how to set orentation
    d.getWindow().setAttributes(lp);
  • http://stackoverflow.com/questions/8035453/set-the-orientation-to-portrait-from-code?answertab=oldest#tab-top – Don Chakkappan Dec 15 '14 at 07:00
  • Why not just make a new Activity and use a dialog style? – Thorben Dec 15 '14 at 08:35
  • Hi is it possible to set orentation at this line:-lp.screenOrientation=WindowManager.LayoutParams. – Amol Chavan Dec 15 '14 at 08:52
  • If I open dialog then my dialog should be in portrait mode and if I close dialog then my activity support both orentation. Also I have added one line in my edited question :-lp.screenOrientation=ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; – Amol Chavan Dec 15 '14 at 09:06

3 Answers3

1

You should check the orientation in that place where you want to show a dialog.

If orientation is portrait then show your dialog.

Community
  • 1
  • 1
QArea
  • 4,955
  • 1
  • 12
  • 22
0

STEP 1: make your activity portrait through manifest using screen orientation

<activity
        android:name="com.example.test.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

STEP 2: where ever required create dialog as below

Dialog dialogBoxAbout = new Dialog(this);
dialogBoxAbout.setContentView(R.layout.activity_about);
dialogBoxAbout.show();

This is for making a dialog through XML.

ANOTHER OPTION
Create a new activity and make it a dialog. Declare it in manifest file as mentioned below.

<activity
        android:name="com.test.dialog"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Dialog" />
Vibhor Chopra
  • 647
  • 4
  • 14
0

To lock orientation if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); }

TO unlock :

        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Amol Desai
  • 872
  • 1
  • 9
  • 17