当前位置: 代码迷 >> Android >> android 普普通通对话框
  详细解决方案

android 普普通通对话框

热度:18   发布时间:2016-05-01 16:47:28.0
android 普通对话框
     string.xml
<?xml version="1.0" encoding="utf-8"?><resources>    <string name="hello">Hello World, Activity01!</string>    <string name="app_name">android_xhtest_01</string>    <string name="btn">显示普通对话框</string>    <string name="title">普通对话框</string>    <string name="ok">确定</string>    <string name="dialog_msg">这是普通对话框的内容!!!</string></resources>


main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    ><EditText	android:text=""	android:id="@+id/EditText01"	android:layout_width="fill_parent"	android:layout_height="wrap_content"	android:editable="false"	android:cursorVisible="false"/><Button	android:text="@string/btn"	android:id="@+id/Button01"	android:layout_width="fill_parent"	android:layout_height="wrap_content"	/></LinearLayout>


    Activity类
package xiaohang.zhimeng;import android.app.Activity;import android.app.AlertDialog;import android.app.Dialog;import android.app.AlertDialog.Builder;import android.content.DialogInterface;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;public class Activity01 extends Activity {	// 普通对话框ID	final int COMMON_DIALOG = 1;	@Override	public void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);		setContentView(R.layout.main);		Button btn = (Button) findViewById(R.id.Button01);		btn.setOnClickListener(new View.OnClickListener() {			public void onClick(View v) {				showDialog(COMMON_DIALOG);			}		});	}	@Override	protected Dialog onCreateDialog(int id) {		Dialog dialog = null;		switch (id) {		case COMMON_DIALOG:			Builder b = new AlertDialog.Builder(this);			b.setIcon(R.drawable.android);			b.setTitle(R.string.btn);			b.setMessage(R.string.dialog_msg);			b.setPositiveButton(R.string.ok,					new DialogInterface.OnClickListener() {						public void onClick(DialogInterface dialog, int which) {							EditText et = (EditText) findViewById(R.id.EditText01);							et.setText(R.string.dialog_msg);						}					});			dialog = b.create();			break;		default:			break;		}		return dialog;	}}

 
运行效果





源码 附件
  相关解决方案