Furqan
Furqan

Reputation: 895

How to show dialog landscape orientation in landscape fragment layout?

Is there any method to show dialog in landscape mode in landscape activity?

This is my dialog showing code:

  Dialog dialog = new Dialog(getActivity());
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.dialog_todays_pick_list);
//       setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        dialog.show();

By using above code dialog is showing in portrait mode.

Upvotes: 1

Views: 3897

Answers (1)

ByteCountTim
ByteCountTim

Reputation: 66

OOPs this is little late but can help some other needy.

To achieve this just follow four basic steps

  1. Create custom layout for Dialog
  2. Inflate layout in Dialog using LayoutInflater class
  3. Take parameters of Window Manager, and set theme as Width="MATCH_PARENT" and Height="WRAP_CONTENT"
  4. Last, set layout parameter to window of Dialog

and for your smiley face, kindly have a look below code snippet.

LayoutInflater inflater = getLayoutInflater();
View dialogView = inflater.inflate(R.layout.dialog_screen, null);

final Dialog dialogShowInfo = new Dialog(mContext);
dialogShowInfo.setContentView(dialogView);
dialogShowInfo.setCancelable(false);

TextView tvInputsValuesAll = 
     dialogShowInfo.findViewById(R.id.tvInputsValuesAll);

     Button btnCncl = dialogShowInfo.findViewById(R.id.btnCncl);
     btnCncl.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View v) {
         dialogShowInfo.dismiss();
     }
});

WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
Window windowAlDl = dialogShowInfo.getWindow();

layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;

windowAlDl.setAttributes(layoutParams);
dialogShowInfo.show();

Upvotes: 1

Related Questions