之前写了一篇android 关于AlertDialog 布局的博文,上次的布局是用setContentView()来进行布局,并强调了一些代码的编写顺序,今天我用setview对alertdialong进行布局。

代码如下:

Java代码
  1. /**
  2. *打开保存对话框框
  3. */
  4. privatevoidopenSaveDialog()
  5. {
  6. savePhotoDialog=newAlertDialog.Builder(SaveAndShareActivity.this);
  7. LayoutInflaterfactory=LayoutInflater.from(SaveAndShareActivity.this);
  8. Viewview=factory.inflate(R.layout.save_dialog_layout,null);
  9. editText=(EditText)view.findViewById(R.id.EditTextPhotoName);
  10. savePhotoDialog.setIcon(R.drawable.icon_save);
  11. savePhotoDialog.setTitle("保存图片");
  12. savePhotoDialog.setView(view);
  13. savePhotoDialog.setPositiveButton("确定",newDialogInterface.OnClickListener(){
  14. publicvoidonClick(DialogInterfacedialog,intwhichButton)
  15. {
  16. savePhotoName=editText.getText().toString();
  17. if(savePhotoName!=null)
  18. {
  19. Toast.makeText(SaveAndShareActivity.this,savePhotoName,Toast.LENGTH_SHORT)
  20. .show();
  21. savePhotoDialog.create().dismiss();
  22. }
  23. else
  24. {
  25. Toast.makeText(SaveAndShareActivity.this,"文件名不能为空!",Toast.LENGTH_SHORT)
  26. .show();
  27. }
  28. }
  29. });
  30. savePhotoDialog.setNegativeButton("取消",newDialogInterface.OnClickListener(){
  31. publicvoidonClick(DialogInterfacedialog,intwhichButton)
  32. {
  33. savePhotoDialog.create().dismiss();
  34. }
  35. });
  36. savePhotoDialog.create().show();
  37. }

布局文件:

Java代码
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="260dip"
  4. android:layout_height="200dip"
  5. android:gravity="center"
  6. android:orientation="vertical">
  7. <TextView
  8. android:id="@+id/TextViewPhotoName"
  9. android:layout_width="200dip"
  10. android:layout_height="wrap_content"
  11. android:text="@string/save_photo_name"
  12. android:textColor="#fff"
  13. android:textSize="20sp"/>
  14. <EditText
  15. android:id="@+id/EditTextPhotoName"
  16. android:layout_width="200dip"
  17. android:layout_height="wrap_content"
  18. android:text="@string/default_photo_name"/>
  19. </LinearLayout>

这些代码摘自我项目的一部分,大家捡一些有用的信息,ok!

注:个人见解,可提意见或建议,勿扔板砖,谢谢!

更多相关文章

  1. Android绘制进阶之四:在位图上绘制文本并旋转
  2. Android侧拉框Demo
  3. Android(安卓)4.1/4.1.1 TextView.setText for Html 引发ArrayIn
  4. H5 调用android原生相机代码分析
  5. android 逆向工程-工具篇 jadx(九)
  6. 菜鸟Android(1)
  7. 浅入浅出Android(007):看看你的手机上有哪些传感器
  8. android的Fragment解析(一行代码引发的思考)
  9. Android(安卓)CoordinatorLayout高级用法之自定义Behavior

随机推荐

  1. Android平板电脑不能全屏显示的问题
  2. 七、Android数据链接更新路由表
  3. Android中xml文件读写
  4. Android 通过OKhttp3进行下载实现版本更
  5. 近百android开源项目贡献
  6. Android 之 WallpaperManager用法
  7. EditText 键盘收回
  8. Android之国际化(在程序内部强制转换语言
  9. Ubuntu 64位编译 android 4.0源码
  10. Android 应用启动时去掉应用图标