自定义的Dialog
来源:互联网 发布:adb打开软件 编辑:程序博客网 时间:2024/06/04 18:30
相信很多人都想做自定义的控件,因为原生控件真的太丑了,今天给大家介绍的是一款自定义Dialog,之前我总觉得自定义Dialog要重写什么,继承什么东西一大堆,其实自定义Dialog是蛮简单的。那就进入正题。
传统的dialog的写法
Dialog alertDialog = new AlertDialog.Builder(this).
setTitle("对话框的标题").
setMessage("对话框的内容").
setIcon(R.drawable.ic_launcher).
create();
alertDialog.show();
自定义步骤
一,新建一个xml文件,在xml文件中布局你需要的dialog的样式,这里你写的样式就是你后面显示额样式
<?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">
<TextView
style="@style/TitleStyle"
android:background="#f00"
android:text="设置密码"/>
<EditText
android:id="@+id/ed_set_psd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="设置密码"/>
<EditText
android:id="@+id/ed_confirm_psd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="设置密码"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/bt_submit"
android:text="确认"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/bt_cancel"
android:text="取消"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
一,使用这个布局,利用setView()这个方法添加一个界面
“`
AlertDialog.Builder bulider = new AlertDialog.Builder(this);
final AlertDialog dialog = bulider.create();
final View dialogview = View.inflate(this,R.layout.dialog_set_psd,null);
dialog.setView(dialogview);
//后面你就可以对自定义Dialog里面的item控件进行操作
bt_submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//主要的功能区域
EditText ed_confirm_psd = (EditText) dialogview.findViewById(R.id.ed_confirm_psd);
EditText ed_set_psd = (EditText) dialogview.findViewById(R.id.ed_set_psd);
String psd = ed_set_psd.getText().toString().trim();
String confirm = ed_confirm_psd.getText().toString().trim();
if (!TextUtils.isEmpty(psd)&&!TextUtils.isEmpty(confirm)){
if (psd.equals(confirm)){
Intent intent = new Intent(HomeActivity.this,TestActivity.class);
startActivity(intent);
}else{
ToastUtil.show(getApplicationContext(),”两次输入的密码不一致”);
}
}else{
ToastUtil.show(getApplicationContext(),”输入不能为空”);
}
}
});
“`
其实这种自定的dialog还是蛮简单的,读者不必采用继承重写等这类方法去自定义 我们在xml文件中写出我们想要的样式即可,功能还是蛮强大.
- 自定义Dialog的方法
- 自定义自己的Dialog
- 自定义自己的Dialog
- 自定义dialog的
- android Dialog的自定义
- 各种自定义的dialog
- 自定义的dialog
- SWT的自定义Dialog
- 自定义可扩性很强的Dialog
- 自定义可扩性很强的Dialog
- 自定义dialog的使用
- 自定义Android的Dialog
- Dialog对话框的自定义
- 王学岗自定义的dialog
- Android 自定义的Dialog
- 自定义dialog的样式
- 自定义的Dialog
- 创建自定义的Dialog
- /etc/profile文件
- 改进改进博客的源代码
- ubuntu tt1-tt6 中文显示
- 利用EXCEL批量提取超链接
- 自建网页项目-蚁族财富网-记录25
- 自定义的Dialog
- MySQL日期数据类型、时间类型使用总结
- 自我讲解
- 用好SciTE的缩写功能
- 有关Nginx的反向代理和负载均衡
- java网络编程(上)
- 几种数据可视化框架分析
- 二叉排序树的插入创建与查找
- Qt之TableWidget、信号、槽