2
因爲我想在對話框中使用FragmentManager
,所以我使用onCreateView
而不是onCreateDialog
。Android DialogFragment - 使用onCreateView並添加對話框按鈕到對話框可能?
如果使用這種方法,我可以設置對話框的標題,但是我找不到如何設置對話框按鈕。通常我會做這createDialog
與AlertDialog ...
問:是否可以使用onCreateView
方法,並使用對話框按鈕?或者只能這樣做,如果我手動添加按鈕到我的視圖資源?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.dialog_exercise_info, null);
// I could include the dialog buttons in the view
// but can I somehow add buttons to the dialog directly?
return v;
}
@Override
protected Dialog createDialog(final Bundle savedInstanceState, Activity activity)
{
Dialog dialog = new Dialog(getActivity(), getTheme());
dialog.setTitle(R.string.title_create_exercise);
return dialog;
}
好的,謝謝。任何其他缺點,如果我不使用AlertDialog?我會然後手動添加按鈕佈局,並相應地調用聽衆... – prom85 2014-10-20 07:06:46
不是。我更喜歡使用我自己的自定義對話框片段,因爲我可以在其他地方重複使用它們。我遵循的技巧是設計Save和Cancel(正面和負面按鈕),具有與AlertDialog相同的透明背景 - 這可以保持設計與Android UI的一致性。 – ucsunil 2014-10-20 16:36:54
我有一個完整的基於總線的對話框片段/片段對話框庫,以及...我只是想知道如果我可以做到這一點,而無需手動添加按鈕。 Thx雖然 – prom85 2014-10-20 19:12:51