2017-06-13 29 views
-2

我在對話框的右上角顯示有箭頭形狀的自定義對話框的要求。我谷歌退出爲,結果我得到了相同的,但是,它的彈出窗口不是DIALOG自定義對話框與三角對話境外在右上角

因爲,我有對話框打開時禁用背後對話框的背景下,彈出窗口是不是在這種情況下使用。雅,我可以禁用與彈出窗口背景觸摸也。但是,我認爲對話是更好的解決方案。

我在我的屏幕上的特定位置成功地打開對話框,現在,我只需要設置對話框中的箭頭(在右上角的三角形)。

我怎樣才能實現這一目標?

謝謝。

回答

0
<?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="@drawable/dialogbox" 
android:orientation="vertical"> 


<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/your_image_arrow" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:padding="16dp" 
    android:text="Do you want to logout" 
    android:textSize="15dp" /> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:background="@android:color/darker_gray" /> 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center"> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <Button 
      android:id="@+id/customDialogCancel" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_toLeftOf="@+id/customDialogOk" 
      android:layout_toStartOf="@+id/customDialogOk" 
      android:layout_weight="1" 
      android:background="@drawable/buttonview" 
      android:text="Cancel" 
      android:textAlignment="center" 
      android:textColor="#00bfff" 
      android:textStyle="bold" /> 

     <View 
      android:layout_width="1dp" 
      android:layout_height="match_parent" 
      android:background="@android:color/darker_gray" /> 


     <Button 
      android:id="@+id/customDialogOk" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_weight="1" 
      android:background="@drawable/buttonview" 
      android:text="Logout" 
      android:textAlignment="center" 
      android:textColor="#00bfff" 
      android:textStyle="bold" /> 

    </LinearLayout> 

</RelativeLayout> 
</LinearLayout> 

,並在你的活動這樣做:

final Dialog dialog = new Dialog(context); 
      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      dialog.setContentView(R.layout.custom_dialog); 
      dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
      // Custom Android Allert Dialog Title 

      Button dialogButtonCancel = (Button) dialog.findViewById(R.id.customDialogCancel); 
      Button dialogButtonOk = (Button) dialog.findViewById(R.id.customDialogOk); 
      // Click cancel to dismiss android custom dialog box 
      dialogButtonCancel.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        dialog.dismiss(); 
       } 
      }); 

      // Your android custom dialog ok action 
      // Action for custom dialog ok button click 
      dialogButtonOk.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        Intent intent = new Intent(CategoryActivity.this, 
LoginActivity.class); 
        startActivity(intent); 
        finish(); 
       } 
      }); 

      dialog.show(); 
     } 
    }); 

我的對話框有取消和註銷按鈕。你可以編寫你自己的功能。希望這會有所幫助。

+0

試圖..感謝.. –

+0

你好先生創建對話框,這個三角形應該出側Dialog的頂部邊框.. –

0

這裏使用我創建了一個自定義對話框,讓你。根據你改變形象: 創建dialog.xml文件:

<?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> 

現在從您的活動

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); 
+0

ya謝謝,正在嘗試.. –

+0

您好先生,這個三角形應該在對話框的頂部邊框的外側.. –

+0

在您想要顯示對話框並通過更改位置來更改位置的活動中使用此代碼wlp.x和wlp.y​​值 – sumit