2012-08-16 26 views
1

我有一個自定義對話框視圖,我用圓角顯示。正因爲如此,我需要隱藏默認的對話邊框,我使用getDialog()。getWindow()。setBackgroundDrawable(new ColorDrawable(0));.Android:當隱藏默認邊框時的DialogFragment包裝內容寬度

我的問題是對話框現在擴展了整個父寬度,我只希望它顯示寬度的90%像一個正常的對話窗口。我試着設置getWindow()。setLayout(...),並設置佈局參數的屬性,但無濟於事。任何幫助深表感謝。

*更新。移除getDialog()。getWindow()。setBackgroundDrawable(new ColorDrawable(0));從我的代碼修復了寬度問題,但讓我回到了默認對話框邊框顯示的問題。雖然由於我的自定義對話框沒有邊框和圓角,我需要邊框消失而不會丟失90%或任何像大多數對話框那樣的對話框寬度。

public final class ResetPasswordDialogFragment extends DialogFragment { 

    public static ResetPasswordDialogFragment newInstance() { 
    ResetPasswordDialogFragment f = new ResetPasswordDialogFragment(); 

    Bundle args = new Bundle(); 
    f.setArguments(args); 

    return f; 
    } 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    View v = inflater.inflate(R.layout.dialog_fragment_password_reminder, container, false); 

    //Removes the default dialog background border 
    getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0)); 

    Button resetBtn = (Button)v.findViewById(R.id.resetPasswordBtn); 
    Button closeBtn = (Button)v.findViewById(R.id.closeBtn); 

    //Click Listeners 
    resetBtn.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      //TODO web call here 
     } 
    }); 
    closeBtn.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      dismiss(); 
     } 
    }); 

    return v; 
    } 
} 
+0

你想設置的寬度和高度動態的? 如果沒有,那麼你可以給你的dialog_fragment_reminder xml文件的layout_width和layout_height參數 – Android2390 2012-08-16 20:37:22

+0

我有這兩個設置爲wrap_content在我的佈局,雖然我也嘗試設置一個固定的寬度像100dp測試和對話窗口仍然填滿整個屏幕。但只有當我隱藏默認的對話框邊框。 – askilondz 2012-08-16 20:41:53

+0

我認爲你需要創建一個自定義對話框,並給它具體的參數:嘗試看看這裏http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog – Android2390 2012-08-16 20:49:26

回答

0

這可能不是你的最佳解決方案,或幫助你在你的示例代碼,但我會做的是創建活動爲您提供的自定義對話框或觸發這樣一個對話的任何事件:

  dialog = new Dialog(getActivity(),R.style.Theme_CustomDialog); 
      dialog.setContentView(R.layout.custom_dialog); 
      dialog.show(); 

,並在您Theme_Custom對話框,如果你要刪除的邊界只是給

 <item name="android:windowNoTitle">true</item> 

,然後在CUSTOM_DIALOG xml文件給你想要的參數的線性/相對佈局通過和你想的看法您的自定義對話框有

或者你可以看看這裏:http://android-developers.blogspot.com/2012/05/using-dialogfragments.htmlhttp://android-er.blogspot.com/2012/01/dialogfragment.html

+0

對不起,這並不能解決我的問題。我很好奇,如果使用DialogFragment會造成某種棘手的問題。我的問題很簡單...我不希望寬度填充父項。儘管設置wrapped_content或事件固定寬度的常識方法並不能解決這個問題。 – askilondz 2012-08-16 21:04:58

相關問題