AlertDialog.Builder弹出各类窗口实现
来源:互联网 发布:mac淘宝 编辑:程序博客网 时间:2024/06/07 04:04
在activity_main.xml添加代码
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="用于显示用资源xml文件定制的AlertDialog" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="AlertDialog.Builder弹出XML自定义Layout窗口" android:id="@+id/btnAlertDialogWithXML" android:onClick="onClicknAlertDialogWithXML" android:layout_gravity="center_horizontal" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="没有资源的AlertDialog" android:id="@+id/btnAlertDialog_NoRes" android:onClick="onClickAlertNoRes" android:layout_gravity="center_horizontal" /><Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="没有资源和按钮的AlertDialog" android:id="@+id/btnAlertDialog_NoResNoBtn" android:onClick="onClickAlertNoResNoBtn" android:layout_gravity="center_horizontal" />
创建资源文件custom_alert_dialog_layout.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="警告对话框用于对客户发出警告信息,而不是用于输入信息,如果要输入信息建议用自定义对话框。自定义资源文件只是为了丰富提示信息。" android:layout_gravity="center_horizontal" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> </LinearLayout> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView" android:src="@drawable/ic_launcher" android:layout_gravity="center_horizontal" /> </LinearLayout>
添加MainActivity.java代码
public class MainActivity extends AppCompatActivity { private DialogInterface dialogWithXml; private TextView tvAlertDialgoUserName,tvAlertDialgoPassword; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onClicknAlertDialogWithXML(View view) { LayoutInflater inflater = LayoutInflater.from(this); View layout=inflater.inflate(R.layout.custom_alert_dialog_layout, null); AlertDialog.Builder builder =new AlertDialog.Builder(this); builder.setView(layout); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); // builder.setCancelable(false); //设置不能按返回键取消 dialogWithXml=builder.create(); builder.show(); } public void onClickAlertNoRes(View view) { AlertDialog.Builder myAlert=new AlertDialog.Builder(this); myAlert.setMessage("这里是AlertDialgo信息,点击确定退出") .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setTitle("这是标题") .setIcon(R.drawable.ic_launcher) .create(); myAlert.show(); } public void onClickAlertNoResNoBtn(View view) { AlertDialog.Builder myAlert=new AlertDialog.Builder(this); myAlert.setMessage("这里是AlertDialgo信息,点击外围自动取消") .create(); myAlert.show(); }}
0 0
- AlertDialog.Builder弹出各类窗口实现
- AlertDialog.Builder弹出自定义Layout窗口
- AlertDialog.Builder弹出自定义Layout窗口
- AlertDialog.Builder弹出自定义Layout窗口
- 弹出对话框AlertDialog.Builder
- 自定义弹出窗口AlertDialog
- 弹出对话框AlertDialog.Builder使用笔记
- Android弹出框PopupWindow,Dialog,AlertDialog.Builder,AlertDialog的一知半解
- AlertDialog 弹出窗口返回键的处理
- AlertDialog.Builder(各种对话框实现)
- AlertDialog.Builder
- AlertDialog.Builder
- AlertDialog.Builder
- AlertDialog.Builder
- AlertDialog.Builder
- AlertDialog和AlertDialog.Builder
- 【弹出】AlertDialog
- atlas 实现弹出窗口
- 使用java实现发送邮件功能
- JQuery使用方法及详解
- PhoneGap/Cordova学习笔记--3.初次使用Cordova插件
- Android APN配置
- IOS CGContext用法
- AlertDialog.Builder弹出各类窗口实现
- Android 外部存储权限分析 .
- DPCM (Dynamic PCM)系列之一:概述
- linux内核链表分析
- facebook/infer静态扫描分析oc代码
- ORACLE 数据库的回滚要求
- Qt 2D绘图
- 30本经典Linux学习和开发教程和资料
- table 样式设定