Android 自定义AlertDialog提交表单

本文介绍了在Android开发中,如何通过自定义AlertDialog来实现数据或表单的提交,避免了为少量数据创建新Activity的冗余,提高了用户体验。详细讲解了创建显示所需布局文件以及使用该布局创建弹窗对话框的步骤。

Android在前端的设计中,有些时候我们需要提交一些数据或表单的时候,由于数据量不是很大,我们没有必要创建一个全新的Activity来提交很少的数据,这样会显得很单调,也浪费资源,其实不只是Android中这样,网页设计也会大量利用弹窗式对话框来提交一些数据。这个时候我们就可以使用自定义的AlertDialog。

1、创建AlertDialog显示所需要的布局文件。这里是一个修改密码的布局文件:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="80dip"
        android:layout_marginStart="20dip"
        android:layout_marginLeft="20dip">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="密       码:"
            />
        <EditText
            android:layout_width="220dp"
            android:inputType="textPassword"
            android:layout_height="wrap_content"
            android:id="@+id/secret"
             />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="20dip"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="确认密码:"
            android:layout_marginStart="20dip"
            android:layout_marginLeft="20dip"
            />



        <EditText
            android:layout_width="220dp"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:id="@+id/confirmSecret" />
    </LinearLayout>

</LinearLayout>

2、使用该布局文件并创建AlertDialog:

//定义一个自定义对话框
AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("设置密码");//设置标题
                View view = LayoutInflater.from(this).inflate(R.layout.activity_set_secret,null);//获得布局信息
                final EditText secret = (EditText) view.findViewById(R.id.secret);
                final EditText confirmSecret = (EditText) view.findViewById(R.id.confirmSecret);
                builder.setView(view);//给对话框设置布局
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //点击确定按钮的操作
                    }
                });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                });
                builder.show();


COZE工作流是一种高效的视频内容创作工具,它能够通过一键操作快速生成高质量的短视频内容。该工作流集成了多种功能,特别适用于创作不同类型的视频项目,如古诗词解读、儿童故事讲述以及沉浸式的叙述历史故事。使用该工具,即便是复杂的视频编辑和制作流程也能轻松完成。COZE工作流对于古诗词的视频化解读提供了极大的便利。用户可以轻松地将古诗词的内容通过视觉和听觉的形式展现出来,使得传统的古诗词以更生动和直观的方式呈现在观众面前。这不仅提升了学习古诗词的兴趣,还使得这类高雅艺术更容易被年轻一代接受和理解。针对儿童故事的视频制作,COZE工作流也展现出其独特的优势。它能够帮助创作者快速将儿童喜爱的故事内容转化为引人入胜的视频作品。视频中的动画效果、角色配音以及背景音乐,都能为孩子们带来更丰富的视听体验,让故事变得更生动和有趣。此外,沉浸式的叙述历史故事也是COZE工作流的亮点之一。通过这种视频制作方式,历史事件和人物可以以一种更生动和直观的形式展现,观众可以在观看的过程中,仿佛身临其境般地体验历史。这种创新的历史教育方式不仅增了学习的趣味性,也增强了历史知识的传播效果。COZE工作流中的“一键生成剪映草稿”功能,意味着用户可以快速得到一个基础的视频草稿,从而省去了大量繁琐的手动编辑过程。这不仅节省了创作者的时间和精力,也使得视频制作过程更高效。另外,它提供的重新制作版本功能,更是为追求更高制作质量的用户提供了一个提升作品品质的机会。在操作上,COZE工作流提供了两种文件导入方式,即一键导入包和手工导入文件。一键导入包功能非常适合那些批量处理视频项目的用户,能够快速完成大量视频的初步编辑工作。而手工导入文件则适用于需要精细调整和个性化编辑的视频项目,用户可以根据自己的需求对素材进行选择和编辑。COZE工作流以其一键生成、高质量输出、多功能集成以及高效操作的
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值