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.
Asked
Active
Viewed 3,697 times
4
-
Refer to https://stackoverflow.com/questions/2115758/how-to-display-alert-dialog-in-android. – hypd09 Dec 16 '15 at 05:36
-
It may help to look at this for ideas: https://www.google.com/design/spec/components/dialogs.html#dialogs-simple-dialogs – Morrison Chang Dec 16 '15 at 05:39
4 Answers
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
-
-
Yes its free , its licenced under MIT Licence https://github.com/pedant/sweet-alert-dialog#license – Veer3383 Dec 16 '15 at 06:06
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