android AlertDialog布局 ——2
之前写了一篇android 关于AlertDialog 布局的博文,上次的布局是用setContentView()来进行布局,并强调了一些代码的编写顺序,今天我用setview对alertdialong进行布局。
代码如下:
?
/** * 打开保存对话框框 */private void openSaveDialog(){savePhotoDialog = new AlertDialog.Builder(SaveAndShareActivity.this);LayoutInflater factory = LayoutInflater.from(SaveAndShareActivity.this);View view = factory.inflate(R.layout.save_dialog_layout, null);editText = (EditText) view.findViewById(R.id.EditTextPhotoName);savePhotoDialog.setIcon(R.drawable.icon_save);savePhotoDialog.setTitle("保存图片");savePhotoDialog.setView(view);savePhotoDialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int whichButton){savePhotoName = editText.getText().toString();if (savePhotoName != null){Toast.makeText(SaveAndShareActivity.this, savePhotoName, Toast.LENGTH_SHORT).show();savePhotoDialog.create().dismiss();}else{Toast.makeText(SaveAndShareActivity.this, "文件名不能为空!", Toast.LENGTH_SHORT).show();}}});savePhotoDialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int whichButton){savePhotoDialog.create().dismiss();}});savePhotoDialog.create().show();}
?
布局文件:
?
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="260dip" android:layout_height="200dip" android:gravity="center" android:orientation="vertical" > <TextView android:id="@+id/TextViewPhotoName" android:layout_width="200dip" android:layout_height="wrap_content" android:text="@string/save_photo_name" android:textColor="#fff" android:textSize="20sp" /> <EditText android:id="@+id/EditTextPhotoName" android:layout_width="200dip" android:layout_height="wrap_content" android:text="@string/default_photo_name" /></LinearLayout>?
这些代码摘自我项目的一部分,大家捡一些有用的信息,ok!
?
注:个人见解,可提意见或建议,勿扔板砖,谢谢!