对话框控件

本文深入探讨了对话框控件在用户界面设计中的重要性,详细解释了其功能和使用场景。从基本概念到高级特性,包括对话框的类型、如何创建和自定义对话框、以及它们在桌面应用程序和移动平台上的实现。通过实例分析,阐述了如何有效地利用对话框增强用户体验。
摘要由CSDN通过智能技术生成
//单选对话框
new AlertDialog.Builder(this)
	.setTitle("请做出你的选择")
	.setIcon(R.mipmap.ic_launcher)
	.setPositiveButton("确认",null)
	.setNegativeButton("取消",null)
	.setSingleChoiceItems(new String[]{"上海", "广东", 
	"北京", "浙江"}, 0, new 
	DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) 						
    {
    
	}
    })
	.create().show();
//多选对话框
AlertDialog dialog=new AlertDialog.Builder(this)
	.setTitle("你的兴趣爱好有哪些")
	.setIcon(R.mipmap.ic_launcher)
	.setMultiChoiceItems(new String[]{"看书","运动","音
	乐","烹饪"},null,null)
    .setPositiveButton("确认",null)
    .setNegativeButton("取消",null)
	.create();
    dialog.show();
//进度条
ProgressDialog prg=new ProgressDialog(this);
	prg.setTitle("进度显示");
	prg.setIcon(R.mipmap.ic_launcher);
	prg.setMessage("正在复制,请稍后");
 	prg.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    prg.show();
//即时对话框
Toast.makeText(this,"您做的是多项选择",Toast.LENGTH_LONG).show();
new AlertDialog.Builder(this)
	.setTitle("提示")
	.setIcon(R.mipmap.ic_launcher)
	.setMessage("确认退出吗?")
   	.setPositiveButton("确认",null)
    .setNegativeButton("取消",null)
    .create().show();
 AlertDialog dialog=new AlertDialog.Builder(this)
 .setTitle("提示")
 .setIcon(R.mipmap.ic_launcher)
 .setMessage("确认退出吗?")
 .setPositiveButton("确认",null)
 .setNegativeButton("取消",null)
 .create();
 dialog.show();
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="下列游戏,您比较喜欢:" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="您选择的是:" />

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="王者荣耀" />

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="和平精英" />

    <CheckBox
        android:id="@+id/checkBox3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="英雄联盟" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPersonName"/>

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:text="默认的" />
</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值