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

好吧,它的对话框工作。我也想删除两侧的填充。谢谢 –

相关问题