Dialogfragment customizing pop-up windows

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.