The code for the String.xml file is as follows:
1<resources>2<string name="app_name"> General dialog box Cases </string>3<string name="btn"> Show Normal dialog box </string>4<string name="title"> General dialog Box </string>5<string name="OK"> OK </string>6<string name="dialog_msg"> This is the content of the normal dialog box!!! </string>7</resources>
The Activity_common_dialog code is as follows:
1<?xml version="1.0"encoding="Utf-8"?>2<LinearLayout3Xmlns:android="http://schemas.android.com/apk/res/android"4android:orientation="Vertical"5Android:layout_width="fill_parent"6android:layout_height="fill_parent">7 8<EditText9android:text=""TenAndroid:id="@+id/eidttext01" Oneandroid:cursorvisible="false" AAndroid:layout_width="fill_parent" -android:layout_height="wrap_content"/> - the<Button -Android:id="@+id/button01" -android:text="@string/btn" -Android:layout_width="fill_parent" +android:layout_height="wrap_content"/> - +</LinearLayout>
The Java file code is as follows:
1 Package Com.example.sample_6_3;2 3 ImportAndroid.app.Dialog;4 ImportAndroid.content.DialogInterface;5 ImportAndroid.support.v7.app.AlertDialog;6 Importandroid.support.v7.app.AppCompatActivity;7 ImportAndroid.os.Bundle;8 ImportAndroid.view.View;9 ImportAndroid.widget.Button;Ten ImportAndroid.widget.EditText; One APublicclassCommondialogactivity extends Appcompatactivity { -final int common_dialog = 1; - @Override the protected void OnCreate (Bundle savedinstancestate) { - super.oncreate (savedinstancestate); - Setcontentview (r.layout.activity_common_dialog); -Button BTN =(Button) Findviewbyid (r.id.button01); + Btn.setonclicklistener (New View.onclicklistener () { - @Override + Public void OnClick (View v) { AShowDialog (Common_dialog); //Show normal dialog box at } - }); - } - protected Dialog oncreatedialog (int id) { -Dialog Dialog = null; //declares a dialog object for returning -Switch (ID) {//to judge an ID in Case Common_dialog: -Alertdialog.builder B =New Alertdialog.builder (this); toB.seticon (R.drawable.dialog); //Settings dialog box icon +B.settitle (R.string.title); //Setting the dialog box title -B.setmessage (R.STRING.DIALOG_MSG); //Settings dialog box display content the B.setpositivebutton ( * R.string.ok, $ New Dialoginterface.onclicklistener () {Panax Notoginseng @Override - Public void OnClick (dialoginterface dialog, int which) { theEditText et =(EditText) Findviewbyid (r.id.eidttext01); +Et.settext (R.STRING.DIALOG_MSG); //Set EditText content A } the }); +Dialog = B.create (); //Generating Dialog Objects - Break; $ Default: $ Break; - } - returnDialog //returns the object of the production dialog the } -}
Effects such as:
Android: Normal dialog Box dialog