-1

I have requirement of displaying custom dialog with Arrow shape at the top-right corner of the dialog. I google out for that and as a result I got the same but, its POPUP window not a DIALOG.

Since, I have to disable background behind dialog when dialog opens, popup window is not usable in such case. Ya, I can disable background touch with popup window also. But, I think dialog is better solution.

I have successfully open dialog at a particular position on my screen and Now, I just have to set the Arrow(triangle at the top-right corner) of the dialog.

How can I achive this ?

Thanks.

ZaptechDev Kumar
  • 164
  • 1
  • 14

1 Answers1

0

Here use this I have created a Custom Dialog for you. Change the image according to you: create a dialog.xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"
        android:layout_gravity="end"
        />
</LinearLayout>

Now create dialog from your activity

View view = getLayoutInflater().inflate(R.layout.dialog,null);
        final AlertDialog myDialog = new AlertDialog.Builder(TestActivity.this)
                .setView(view)
                .create();
        infoDialog.show();

Window window = myDialog.getWindow();
                WindowManager.LayoutParams wlp = window.getAttributes();
//change the value of x and y to change the position of dialog box on the screen
                wlp.x = 100;
                wlp.y = 100;

                wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
                window.setAttributes(wlp);
sumit
  • 1,047
  • 1
  • 10
  • 15
  • use this code inside your activity where you want to show the dialog and change position by changing the wlp.x and wlp.y values – sumit Jun 13 '17 at 07:05