使用onCreateView一直試圖弄清楚這一點,現在一會兒:自定義視圖在DialogFragment
我試圖創建一個使用在Dev site所示的標準方法的自定義對話框。
public class CustomDialog extends DialogFragment {
private OnDialogResultListener mOnDialogResultListener = null;
public void setOnDialogResultListener(OnDialogResultListener dialogResultListener) {
mOnDialogResultListener = dialogResultListener;
}
public static CustomDialog newInstance(OnDialogResultListener dialogResultListener) {
CustomDialog frag = new CustomDialog();
frag.setOnDialogResultListener(dialogResultListener);
return frag;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getDialog().setTitle(getString(R.string.Dialog_CustomDialog_Title));
View v = inflater.inflate(R.layout.customdialog, container, false);
return v;
}
}
隨着XML之中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent" android:background="@color/white" android:layout_margin="0px" android:layout_width="fill_parent">
<EditText android:hint="@string/Dialog.CustomDialog.OldPassword" android:layout_marginBottom="@dimen/normalMargin" android:layout_height="wrap_content" android:inputType="textPassword" android:id="@+id/EditText02" android:layout_width="fill_parent"></EditText>
<EditText android:hint="@string/Dialog.CustomDialog.NewPassword" android:layout_height="wrap_content" android:inputType="textPassword" android:id="@+id/EditText01" android:layout_width="fill_parent"></EditText>
<EditText android:hint="@string/Dialog.CustomDialog.RetypePassword" android:layout_height="wrap_content" android:inputType="textPassword" android:id="@+id/editText1" android:layout_width="fill_parent">
<requestFocus></requestFocus>
</EditText>
<LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="fill_parent">
<Button android:layout_height="wrap_content" android:text="@string/save" android:layout_width="@dimen/normalButtonWidth" android:id="@+id/btn_Custom_save"></Button>
<Button android:layout_height="wrap_content" android:text="@string/cancel" android:layout_width="@dimen/normalButtonWidth" android:id="@+id/btn_Custom_cancel"></Button>
</LinearLayout>
</LinearLayout>
以及創建和顯示對話框後,我留下了:
白色背景已應用於強調意外和不想要的行爲。
任何想法?我試過改變寬度/高度,在水平LinearLayout中使用權重,以編程方式設置寬度/高度 - 都無濟於事。
我會檢查一次,我得到它,並給你信用,如果它的工作:) –