1

I need to use my AppCompat Activity as a Dialog.For this I tried so my solution that answered in StackOverflow. But nothing worked.Please answer me. I am getting activity as dialog. But it shows very narrow both in height & width.

I used the following Theme:

<style name="AppDialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="windowNoTitle">true</item>
    <item name="android:background">@android:color/transparent</item>
</style>

enter image description here

Parama Sudha
  • 2,583
  • 3
  • 29
  • 48
  • Is your question somehow aiming for the window of the dialog itself? To MATCH_PARENT both? Something similar to this -- http://stackoverflow.com/questions/11613825/how-to-create-dialog-which-will-be-full-in-horizontal-dimension --? – AL. Mar 09 '16 at 05:14
  • You can also try adding the ***true***, http://stackoverflow.com/questions/9859220/full-screen-in-customize-theme – AL. Mar 09 '16 at 05:17
  • Sorry...I have not gotten it.I uploaded a screenshot of what I am getting. – Parama Sudha Mar 09 '16 at 05:24
  • please [check this](http://stackoverflow.com/a/35883463/2826147) answer. – Amit Vaghela Mar 09 '16 at 05:26
  • Have you seen this references -- http://stackoverflow.com/questions/10398665/how-can-i-make-my-android-dialog-fullscreen, http://stackoverflow.com/questions/1362723/how-can-i-get-a-dialog-style-activity-window-to-fill-the-screen -- and tried it out? I think the easiest way to do this is by getting the Window reference of the Dialog and setting its LayoutParams. – AL. Mar 09 '16 at 05:32

2 Answers2

0

You can use DialogFragment and customize the layout accordingly.

public class CustomDialogFrag extends DialogFragment{
static FragmentManager fragmentManager;
    public static CustomDialogFrag showDialog(FragmentManager fm){
        CustomDialogFrag customDialogFrag=new CustomDialogFrag();
        fragmentManager=fm;
        return customDialogFrag;
    }
@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
           AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
        View view = getActivity().getLayoutInflater().inflate(R.layout.dialogfrag_layout, null);
        alertDialogBuilder.setView(view);
        setupUI(view);
        alertDialogBuilder.setTitle("Notification Message");
        alertDialogBuilder.setIcon(R.drawable.notificationicon);
        alertDialogBuilder.setPositiveButton("Close", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        return alertDialogBuilder.create();
    }
void setupUI(View view){
        TextView textViewOne=(TextView)view.findViewById(R.id.txtEventAlias);
        TextView textViewTwo=(TextView)view.findViewById(R.id.txtTime);
        TextView textViewThree=(TextView)view.findViewById(R.id.txtLogMessage);
        textViewOne.setText("Text 1");
        textViewTwo.setText("Text 2");
        textViewThree.setText("Text 3");
    }
}


And the dialogfrag_layout.xml will be

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/margin_10"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/txtEventAlias"
        android:text="Sample"
        android:textColor="@android:color/darker_gray"
        android:textSize="@dimen/textSizeMedium"
        android:padding="@dimen/margin_10"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/txtTime"
        android:text="Sample"
        android:textColor="@android:color/darker_gray"
        android:textSize="@dimen/textSizeMedium"
        android:padding="@dimen/margin_10"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/txtLogMessage"
        android:text="Sample"
        android:textColor="@android:color/darker_gray"
        android:textSize="@dimen/textSizeMedium"
        android:padding="@dimen/margin_10"
        />
</LinearLayout>

For invoking this Dialog from a Fragment:

DialogFragment dialogFragment=CustomDialogFrag.showDialog(getFragmentManager());
dialogFragment.show(getActivity().getFragmentManager(), "tag");
Sreehari
  • 5,621
  • 2
  • 25
  • 59
0

In your activity's onCreate put the following lines:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_your);

    // Make the window's width full sized
    WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
    Window window = getWindow();

    layoutParams.copyFrom(window.getAttributes());
    layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;

    window.setAttributes(layoutParams);
}

Tested and works. You can set to both width and height to WRAP_CONTENT if needed.

Tamás Cseh
  • 3,050
  • 1
  • 20
  • 30