arent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_marginBottom="4dp"
? ? ? ? android:layout_marginLeft="4dp"
? ? ? ? android:layout_marginRight="4dp"
? ? ? ? android:layout_marginTop="16dp"
? ? ? ? android:hint="input username"
? ? ? ? android:inputType="textEmailAddress" />
? ? ? ? ? ? android:id="@+id/id_txt_password"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_marginBottom="16dp"
? ? ? ? android:layout_marginLeft="4dp"
? ? ? ? android:layout_marginRight="4dp"
? ? ? ? android:layout_marginTop="4dp"
? ? ? ? android:fontFamily="sans-serif"
? ? ? ? android:hint="input password"
? ? ? ? android:inputType="textPassword" />
b)继承DialogFragment重写onCreateDialog方法
package com.example.zhy_dialogfragment;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
public class LoginDialogFragment extends DialogFragment
{
?@Override
?public Dialog onCreateDialog(Bundle savedInstanceState)
?{
? AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
? // Get the layout inflater
? LayoutInflater inflater = getActivity().getLayoutInflater();
? View view = inflater.inflate(R.layout.fragment_login_dialog, null);
? // Inflate and set the layout for the dialog
? // Pass null as the parent view because its going in the dialog layout
? builder.setView(view)
? ? // Add action buttons
? ? .setPositiveButton("Sign in",
? ? ? new DialogInterface.OnClickListener()
? ? ? {
? ? ? ?@Override
? ? ? ?public void onClick(DialogInterface dialog, int id)
? ? ? ?{
? ? ? ?}
? ? ? }).setNegativeButton("Cancel", null);
? return builder.create();
?}
}
c)调用
public void showLoginDialog(View view)
?{
? LoginDialogFragment dialog = new LoginDialogFragment();
? dialog.show(getFragmentManager(), "loginDialog");
?}
效果图:

可以看到通过重写onCreateDialog同样可以实现创建对话框,效果还是很nice的。