Question :
I’m trying to make a custom popup, similar to the one in the photo, by putting a close button at the top and centering it in the middle of the screen, does anyone know how I do it?
I searched for some codes, but nothing very complete
Answer :
With DialogFragment you get that way below
mButton.setOnclickListener(new OnclickListener(){
test();
});
public void test(){
Dialog dialog = new Dialog(this, R.style.FullHeightDialog);
dialog.setContentView(R.layout.seu_layout_customizado);
dialog.show();
}
Creating XML
- Create a root LinearLayout
- Creates another LinearLayout with vertical orientation, where it will contain the X button, title, and description.
- Creates a View (
<View android_layout_width="fill_parent" android_layout_height="1dp"/>
) to represent the line. To represent this grouping of icons and text (gps, wifi and wireless network) creates a RelativeLayout. -
For the confirmation button, add in the LinearLayout root.
<LinearLayout xmlns_android="http://schemas.android.com/apk/res/android" android_layout_width="match_parent" android_layout_height="match_parent"> <ImageView android_layout_width="match_parent" android_layout_height="wrap_content" android_background="x"/> <TextView android_layout_width="wrap_content" android_layout_height="wrap_content" android_text="Melhore..."/> <TextView android_layout_width="wrap_content" android_layout_height="wrap_content" android_text="Para garantir..."/> <RelativeLayout android_layout_width="wrap_content" android_layout_height="wrap_content"> gps rede wifi </RelativeLayout> <Button android_layout_width="wrap_content" android_layout_height="wrap_content" />