Android Initial Learning-dialogfragment Create dialog box __android

Source: Internet
Author: User
1. OverviewDialogfragment was introduced when Android was 3.0. is a special fragment for displaying a modal dialog box over the content of an activity. Typical for: Display warning boxes, input boxes, confirmation boxes, and so on.
Before dialogfragment, we create dialog boxes: generally using Alertdialog and dialog. Note: The official does not recommend to use dialog to create a dialog box directly.
2. Benefits and UsageUsing Dialogfragment to manage the dialog box, you can better manage its declaration cycle when you rotate the screen and press the back key, which has a basically consistent declaration cycle with fragment. And Dialogfragment also allows developers to reuse dialog as an embedded component, similar to fragment (which can show different effects on large and small screens). The above will show these benefits by example

Using dialogfragment requires at least the implementation of Oncreateview or Oncreatedialog methods. Oncreateview shows dialog using the defined XML layout file. Oncreatedialog uses Alertdialog or dialog to create a dialog. 3. Rewrite oncreateview Create dialog

A) layout file, we create a layout file with the name set:

[HTML]  View Plain Copy <?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"  >           <TextView            android:id= "@+id/id_label_your_name"            android: Layout_width= "Wrap_content"            android:layout_height= " 32DP "           android:gravity=" center_vertical            android:text= "Your name:"  />           <EditText           android: Id= "@+id/id_txt_your_name"            android:layout_width= " Match_parent "           android:layout_height=" Wrap_content "            android:layout_torightof= "@id/id_label_your_name"            android:imeoptions= "Actiondone"             android:inputtype= "text"  />           <Button           android:id= "@+id/id_ Sure_edit_name "           android:layout_width=" Wrap_content "            android:layout_height= "Wrap_content"            android:layout_alignparentright= "true"             android:layout_below= "@id/id_txt_your_name"             android:text= "OK"  />      </RelativeLayout>  
b inheriting Dialogfragment, overriding Oncreateview methods

[Java] view plain copy package com.example.zhy_dialogfragment;

Related Article

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.