0

匹配的父在OnCreateDialog我這樣做:alertdialog正/負按鈕沒有在我的dialogfragment類全屏dialogfragment

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
     inflater=getActivity().getLayoutInflater(); 
     v=inflater.inflate(R.layout.new_spending_fragment_layout,null); 
     builder.setPositiveButton("Fire", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) { 
         // FIRE ZE MISSILES! 
        } 
       }); 
     builder.setView(v); 
     return builder.create(); 

處理通信在dialogfragment類我想提出的dialogfragment全屏

Dialog d = getDialog(); 
     if (d!=null){ 
      int width = ViewGroup.LayoutParams.MATCH_PARENT; 
      int height = ViewGroup.LayoutParams.MATCH_PARENT; 
      d.getWindow().setLayout(width, height); 
     } 

我想讓alertdialog中的正面按鈕(Fire)顯示在底部。

模擬器預覽:

enter image description here

我正在膨脹的佈局具有高度和寬度設置爲匹配父。

我已經在我膨脹的佈局(R.layout.new_spending_fragment_layout)中添加了一個空視圖,並將它的參數設置爲匹配在xml中修正問題的父項,但我認爲這是一個臨時答案。

我也想從各個方面刪除填充(或空白)。

回答

0

試試這個,Dialog with fullscreen screenshot

1 - 創建對話框

Dialog dialog = new Dialog(this, android.R.style.Theme_Light_NoTitleBar); // Replace this line 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.setContentView(R.layout.dialog_layout); 
    dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); 
    dialog.show(); 

2 - dialog_layout.xml

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

    <LinearLayout 
     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="Hello this is demo textview" 
      android:textColor="@color/black" 
      android:textSize="18sp" /> 

    </LinearLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal" 
     android:layout_marginBottom="10dp" 
     android:layout_marginRight="10dp"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:text="Fire" 
      android:background="@null"/> 

    </RelativeLayout> 
</RelativeLayout> 
+0

我不能在一個視圖中添加子視圖。所以我改變了你的看法到linearlayout,但它不適合它(或任何視圖組我猜)。嘗試在視圖中添加任何文本視圖或按鈕作爲子視圖。 –

+0

嗯,我認爲你必須創建與自定義視圖對話框,我修改了代碼,看看,讓我知道另一個查詢 – Bhavnik

+0

好吧,它的對話框工作。我也想刪除兩側的填充。謝謝 –

相關問題