Search code examples
androidmenupopupdevelopment-environment

How to create this type of popup dialogue in Android?


This image took from Deep Relax app from Play Store:

this image took from deep relax app from play store

How do I create a popup menu? I am creating an app I want to ask the user to provide feedback?


Solution

  • Try this use custom dialog for this purpose:

    Create layout like this custom_dialog_layout:

    <?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:orientation="vertical">
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="title"
        android:textColor="#000" />
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting," />
    
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="description" />
    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@null"
            android:id="@+id/btnNotNOw"
            android:text="not now"
            android:textColor="#040d28" />
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:background="@null"
            android:text="Never"
            android:id="@+id/btnNever"
            android:textColor="#040d28" />
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:background="@null"
            android:text="sure"
            android:id="@+id/btnSure"
            android:textColor="#040d28" />
    
    </LinearLayout>
    
     </LinearLayout>
    

    Now create dialog using below code:

     final Dialog dialog = new Dialog(LoginActivity.this);
        dialog.setContentView(R.layout.custom_dialog_layout);
        Button btnNotNOw, btnNever, btnSure;
        btnNotNOw = (Button) dialog.findViewById(R.id.btnNotNOw);
        btnNever = (Button) dialog.findViewById(R.id.btnNever);
        btnSure = (Button) dialog.findViewById(R.id.btnSure);
        Window window = dialog.getWindow();
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        window.setGravity(Gravity.BOTTOM);
        dialog.show();
    
        btnNever.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               // perform your action here 
            }
        });
        btnNotNOw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               // perform your action here 
            }
        });
        btnSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               // perform your action here 
            }
        });