自定义dialog,并且有Edittext,确定按钮获取Edittext的值
来源:互联网 发布:python 爬虫多进程 编辑:程序博客网 时间:2024/05/22 12:41
1、先上布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="50dp"
android:background="@android:color/transparent">
<RelativeLayout
android:id="@+id/rl_dialog_content"
android:layout_width="fill_parent"
android:layout_height="400dp"
android:background="@drawable/bg_btn">
<TextView
android:visibility="gone"
android:id="@+id/dialog_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="50dp"
android:gravity="center"
android:maxLines="5"
android:text="现在就打电话给客服:arjinmc" />
<EditText
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="150dp"
android:id="@+id/edit_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25sp"
android:hint="输入密码"
android:background="@drawable/bg_btn"
/>
<LinearLayout
android:id="@+id/ll_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="30dp"
android:orientation="horizontal">
<!-- style="@style/dialog_button"-->
<Button
android:id="@+id/dialog_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/bg_btn4"
android:text="取消"
android:textColor="@color/colorAccent3" />
<!--style="@style/dialog_button"-->
<Button
android:id="@+id/dialog_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="@drawable/bg_btn4"
android:textColor="@color/colorAccent3"
android:text="确定" />
</LinearLayout>
</RelativeLayout>
<ImageButton
android:visibility="gone"
android:id="@+id/dialog_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="@mipmap/dialogclose" />
</RelativeLayout>
2.布局的效果图
3.实现代码:
private void showCustomizeDialog2() {
LayoutInflater inflaterDl = LayoutInflater.from(this);
final RelativeLayout layout = (RelativeLayout) inflaterDl.inflate(R.layout.dialog2, null);
final Dialog dialog = new Dialog(MainActivity.this);
dialog.create();
dialog.show();
dialog.getWindow().setContentView(layout);
//取消按钮
Button btnCancel = (Button) dialog.findViewById(R.id.dialog_cancel);
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "取消", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
//确定按钮
Button btnOK = (Button) dialog.findViewById(R.id.dialog_ok);
edit_password = (EditText) dialog.findViewById(R.id.edit_password);//输入密码
btnOK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
password = edit_password.getText().toString();
if (password.equals("sport12345")) {
PassWordFLAG = true;
Toast.makeText(MainActivity.this, "密码正确", Toast.LENGTH_SHORT).show();
dialog.dismiss();
} else {
Toast.makeText(MainActivity.this, "密码错误", Toast.LENGTH_SHORT).show();
}
}
});
//关闭按钮
ImageButton btnClose = (ImageButton) layout.findViewById(R.id.dialog_close);
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
- 自定义dialog,并且有Edittext,确定按钮获取Edittext的值
- 关于 listview里面有EditText,然后想改变editText的值并且可以获取
- 在dialog中获取Edittext的值
- 在dialog中获取Edittext的值
- 自定义EditText:带清除按钮的EditText
- 自定义dialog对话框获取EditText数据demo
- Dialog上的EditText的自定义键盘
- 关于获取dialog中edittext的值问题
- 自定义EditText-带清除所有输入按钮的EditText
- 最近项目有需要判断多个EditText是否正确,并且让出错的EditText获取焦点,变换背景色
- 自定义Dialog,带EditText的Match_parent的Dialog
- 自定义带删除按钮的EditText
- 自定义带删除按钮的EditText
- 自定义控件--带有删除按钮的EditText
- Android 自定义带有清除按钮的Edittext
- 自定义控件 带删除按钮的EditText
- android中自定义dialog中有editText,无法显示输入法对话框的解决办法
- Android 自定义Dialog 里面有EditText控件点击关闭输入法失效的问题
- 搭建ELK日志分析系统(三)-Logstash安装和使用
- vim常用命令
- @RequestBody, @ResponseBody 注解
- HTTP协议简单总结
- Keras训练辅助工具及优化工具
- 自定义dialog,并且有Edittext,确定按钮获取Edittext的值
- I/O模式
- 上传文件
- 14:大象喝水
- C# WebApi 上传文件
- 2017暑假第二阶段第九场 总结
- 乘积最大子序列-LintCode
- 同步异步与阻塞非阻塞
- 【简趣学习文本挖掘】用Python带你走进神秘的“谍纸天眼”...