Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom dialog with close button

I want to create a custom dialog with the layout as shown in the picture. enter image description here The cross/close button must be on the top right side. Please suggest how can i achieve this kind of layout.

Thanks in advance.

like image 210
Akshay Sethi Avatar asked Nov 28 '13 05:11

Akshay Sethi


People also ask

How do I add close button to alert box?

setNegativeButton("No",new DialogInterface. OnClickListener() { public void onClick(DialogInterface dialog,int id) { // if this button is clicked, just close // the dialog box and do nothing dialog. cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder. create(); // show it alertDialog.

How do you put a close button at top corner in alert dialog box for flutter?

Modify your class to retrieve a function from Stateful Widget. Pass your Navigator. pop(context) action to that function when showing your popup. Inside the popup class, use that passed function to dismiss itself.

How do I close alert dialog in flutter?

The below code will close AlertBox/DialogBox in Flutter. Navigator. of(context). pop();

How many Action button can a dialog have?

There should be no more than three action buttons in a dialog.


4 Answers

Relative layout will be your parent one and then add close button apply android:layout_alignParentRight="true" and android:layout_alignParentTop="true" and even give right and top margin in minus as per your requirement.

Code

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="255dp"
        android:layout_height="385dp"
        android:layout_centerInParent="true"
        android:background="@color/white"
        android:orientation="vertical" >
    </LinearLayout>

    <Button
        android:id="@+id/button_close"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/relativeLayout1"
        android:layout_alignTop="@+id/relativeLayout1"
        android:layout_marginRight="-10dp"
        android:layout_marginTop="-10dp"
        android:background="@drawable/close" />

</RelativeLayout>

Output

enter image description here

like image 158
RobinHood Avatar answered Oct 18 '22 20:10

RobinHood


might be below code is useful for you,achieved like this

<?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="wrap_content"
    android:layout_gravity="center_vertical"
    android:gravity="center"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/popup_password_latest"
            android:gravity="center"
            android:orientation="vertical"
            android:paddingBottom="-50dp" >

          <!---add your views here-->
        </LinearLayout>

        <ImageView
            android:id="@+id/imageView_close"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top|right"
            android:clickable="true"
            android:src="@drawable/close_selector" />
    </FrameLayout>

</LinearLayout>
like image 25
Pinki Avatar answered Oct 18 '22 22:10

Pinki


Here I have one solution for that. enter image description here

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" >

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="15dp" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@drawable/img_popup_one"
            android:orientation="vertical"
            android:padding="10dp" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Sign In"
                android:textColor="@color/clr_gray"
                android:textSize="16dp" />

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:background="@drawable/img_edittext_bg"
                android:hint="Username"
                android:padding="5dp"
                android:singleLine="true"
                android:textColorHint="@color/clr_gray" />

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:background="@drawable/img_edittext_bg"
                android:hint="Password"
                android:inputType="textPassword"
                android:padding="5dp"
                android:singleLine="true"
                android:textColorHint="@color/clr_gray" />
        </LinearLayout>
    </FrameLayout>

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_gravity="right|top"
        android:contentDescription="@string/contentDescription"
        android:src="@drawable/img_popup_close" />
</FrameLayout>

like image 3
Jigar Brahmbhatt Avatar answered Oct 18 '22 22:10

Jigar Brahmbhatt


You can use PopupWindow here. You can Make a layout for your custom dialog and can inflate that layout in PopupWindow.It should be something like this:-

PopupWindow menuPopup;
menuView=getLayoutInflater().inflate(R.layout.layout_menu, null);
menuPopup=new PopupWindow(menuView, 200, 200, false);
menuPopup.showAtLocation(menuView, Gravity.TOP | Gravity.RIGHT, 0, 100); 
like image 2
Ravneet Singh Avatar answered Oct 18 '22 22:10

Ravneet Singh