Layout file
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:orientation= "Vertical"
android:background= "#00FFFFFF" >
<imageview
Android:id= "@+id/id_txt"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_centerhorizontal= "true"
android:contentdescription= "@string/app_name"
Android:scaletype= "Center"
android:src= "@drawable/title"/>
<!--android:background= "#FFFFBB33"-
<edittext
Android:id= "@+id/id_txt_username"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
Android:layout_marginbottom= "4DP"
android:layout_marginleft= "4DP"
android:layout_marginright= "4DP"
android:layout_margintop= "16DP"
android:layout_below= "@id/id_txt"
Android:hint= "Input username"
Android:inputtype= "Textemailaddress"/>
<edittext
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:layout_below= "@id/id_txt_username"
Android:fontfamily= "Sans-serif"
android:hint= "Input Password"
Android:inputtype= "Textpassword"/>
</RelativeLayout>
Fragment file
Package com.qykl.dialogfragment;
Import COM.EXAMPLE.DILAOGFRAGDEMO.R;
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.widget.EditText;
public class Logindialogfragment extends Dialogfragment
{
Private EditText Musername;
Private EditText Mpassword;
public interface Logininputlistener
{
void Onlogininputcomplete (string username, string password);
}
@Override
Public Dialog Oncreatedialog (Bundle savedinstancestate)
{
Alertdialog.builder Builder = new Alertdialog.builder (getactivity ());
Layoutinflater inflater = getactivity (). Getlayoutinflater ();
View view = Inflater.inflate (R.layout.fragment_login_dialog, NULL);
Musername = (EditText) View.findviewbyid (r.id.id_txt_username);
Mpassword = (EditText) View.findviewbyid (R.id.id_txt_password);
Builder.setview (view)
. Setpositivebutton ("Sign In",
New Dialoginterface.onclicklistener ()
{
@Override
public void OnClick (Dialoginterface dialog, int id)
{
Logininputlistener listener = (Logininputlistener) getactivity ();
Listener.onlogininputcomplete (musername
. GetText (). toString (), Mpassword
. GetText (). toString ());
}
}). Setnegativebutton ("Cancel", null);
return Builder.create ();
}
}
Called in the main program
Logindialogfragment dialog = new Logindialogfragment ();
Dialog.show (Getfragmentmanager (), "Logindialog");
If you need to interact
You can add interface in the dialog
Perform machine interaction
Dialogfragment customizing pop-up windows