我有一個自定義對話框視圖,我用圓角顯示。正因爲如此,我需要隱藏默認的對話邊框,我使用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;
}
}
你想設置的寬度和高度動態的? 如果沒有,那麼你可以給你的dialog_fragment_reminder xml文件的layout_width和layout_height參數 – Android2390 2012-08-16 20:37:22
我有這兩個設置爲wrap_content在我的佈局,雖然我也嘗試設置一個固定的寬度像100dp測試和對話窗口仍然填滿整個屏幕。但只有當我隱藏默認的對話框邊框。 – askilondz 2012-08-16 20:41:53
我認爲你需要創建一個自定義對話框,並給它具體的參數:嘗試看看這裏http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog – Android2390 2012-08-16 20:49:26