Пользовательский вид с использованием onCreateView в DialogFragment - PullRequest
1 голос
/ 27 октября 2011

Некоторое время пытался выяснить это:

Я пытаюсь создать собственный диалог, используя стандартный подход, показанный на сайте Dev .

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>

И после создания и показа диалога у меня осталось: enter image description here

Белый фон был применен, чтобы подчеркнуть неожиданное и нежелательное поведение.

Есть идеи? Я пытался изменить ширину / высоту, используя веса в горизонтальном LinearLayout, программируя ширину / высоту - все безрезультатно.

Ответы [ 5 ]

2 голосов
/ 29 декабря 2012

Я нашел следующие уловки: getDialog (). GetWindow (). SetBackgroundDrawableResource (R.color.white);

Похоже, лучшее решение.

1 голос
/ 27 октября 2011

Я придумал дешевое исправление, которое я бы предпочел не использовать.

Добавление высоты 0px, ширины 2000dp (некоторое огромное число) в любом месте макета приводит к заполнению диалогового окна.

0 голосов
/ 11 ноября 2013

В моем случае я использовал относительное расположение в качестве корневого представления, и оно фактически заполнило диалоговые окна.

0 голосов
/ 24 августа 2012

Если вы установили attachToRoot = true во время inflater.inflate, он должен отображать диалог правильно.

View v = inflater.inflate(R.layout.customdialog, container, true);
0 голосов
/ 05 декабря 2011

С DialogFragment ширина и высота равны нулю.Создайте дополнительную группу подвидов с заполнением родителя, и она должна работать для вас.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_height="fill_parent"  
  android:layout_width="fill_parent">

        <LinearLayout android:orientation="vertical"
  android:layout_height="fill_parent" android:background="@color/white" android:layout_margin="0px" android:layout_width="fill_parent">

.....

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...