自定义Dialog,带EditText的Match_parent的Dialog

本文分享了在项目中遇到的使用popupWindow无法输入的问题及解决方案。通过采用Dialog实现了既能调起软键盘又能进行编辑输入的功能,并提供了两种类型的Dialog示例:一种居中显示并附带确定和取消按钮;另一种则位于屏幕底部且包含EditText组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近做项目用到了需要可点击,可调起软键盘编辑输入的弹窗,本来用popupWindow做的,虽然能调起软键盘但是不能输入,不知道什么原因,有知道的哥们可以回复下我

现在改用Dialog,顺便从项目中提取出一个demo,分享给需要的兄弟

先上效果图

1 总共有两种dialog  一种是居中的可以有确定和取消的按钮,也可以只有一个确定按钮的dialog


2 第二种是带EditText,能编辑输入的,显示在底部的Dialog




demo链接:点击打开链接



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="16dp"> <EditText android:id="@+id/et_zujian_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="输入组件名称"/> <EditText android:id="@+id/et_bancai_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="输入板材名称(可选)" android:layout_marginTop="8dp"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="材质选择" android:layout_marginTop="16dp"/> <Spinner android:id="@+id/spinner_caizhi" android:layout_width="match_parent" android:layout_height="wrap_content"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="木皮1" android:layout_marginTop="8dp"/> <Spinner android:id="@+id/spinner_mupi1" android:layout_width="match_parent" android:layout_height="wrap_content"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="木皮2(可选)" android:layout_marginTop="8dp"/> <Spinner android:id="@+id/spinner_mupi2" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> // 添加木皮预览标签 TextView previewMupi1 = dialogView.findViewById(R.id.tv_preview_mupi1); TextView previewMupi2 = dialogView.findViewById(R.id.tv_preview_mupi2);
最新发布
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值