4

I am new in android development so i need to know which is perfect and efficient way to making popup like this in android, basically in iOS it was easy to make popup and handling but how to start with this is using layout or something like that please refer me a link or guide to make popover in android for open over a Activity.

Nicky
  • 885
  • 9
  • 21

4 Answers4

4
private PopupWindow pwindo;
private void initiatePopupWindow() {
        try {
// We need to get the instance of the LayoutInflater
            LayoutInflater inflater = (LayoutInflater) AndroidAudioPlayer.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.your_layout_Screen,
                    (ViewGroup) findViewById(R.id.popup_element));
            pwindo = new PopupWindow(layout, 400, 600, true);
            pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);

            Button btnClosePopup = (Button) layout.findViewById(R.id.button);
            btnClosePopup.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    pwindo.dismiss();
                }
            });

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

For more trendy and good looking alert dialogs, take a look at this library Pedant's Sweet alert dialogs

Veer3383
  • 1,785
  • 6
  • 29
  • 49
1

Try PopupWindow; you can see an example here.

scorpiodawg
  • 5,612
  • 3
  • 42
  • 62
Lan Nguyen
  • 785
  • 5
  • 13
1

You can use PopupWindow .

It is defined as a window that appears in front of your activity on the screen after certain event takes place or certain terms and conditions matched. This window is usually used to display some information and provide controls to perform operations. Popup window also have their own GUI which must be set in its content view.

Complete demo PopupWindow in Android

private PopupWindow pw;
private void initiatePopupWindow() {
    try {
        //We need to get the instance of the LayoutInflater, use the context of this activity
        LayoutInflater inflater = (LayoutInflater) ConfirmActivity.this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //Inflate the view from a predefined XML layout
        View layout = inflater.inflate(R.layout.popup_layout,
                (ViewGroup) findViewById(R.id.popup_element));
        // create a 300px width and 470px height PopupWindow
        pw = new PopupWindow(layout, 300, 470, true);
        // display the popup in the center
        pw.showAtLocation(layout, Gravity.CENTER, 0, 0);

        mResultText = (TextView) layout.findViewById(R.id.server_status_text);
        Button cancelButton = (Button) layout.findViewById(R.id.end_data_send_button);
        makeBlack(cancelButton);
        cancelButton.setOnClickListener(cancel_button_click_listener);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

private OnClickListener cancel_button_click_listener = new OnClickListener() {
    public void onClick(View v) {
        pw.dismiss();
    }
};
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

Here,s can help you : Create one xml name ccc.xml in layout folder :

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffee"
android:orientation="vertical"
android:theme="@style/AppTheme.NoActionBar"
>


<ImageView
    android:layout_width="60dp"
    android:layout_marginTop="100dp"
    android:layout_height="60dp"
    android:layout_gravity="center_horizontal"
    android:src="@drawable/check"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_height="wrap_content"
    android:text="Invitaton Sent Sucessfully"
    android:layout_gravity="center_horizontal"
    android:textStyle="bold"
    android:textSize="15dp"
    /></LinearLayout>

Then write this where you want to call:

 b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Dialog d=new Dialog(MainActivity.this);
            d.setContentView(R.layout.ccc);
            d.show();



        }
    });
Anil Prajapati
  • 457
  • 3
  • 10