android自定义 dialog
来源:互联网 发布:超级软件txt下载 编辑:程序博客网 时间:2024/05/18 12:40
这里以customer_dialog为例子
/** * 自定义dialog样式 * * @author cyp * */public class CustomerDialog {Context context;Dialog dialog;Button sure, cancle;TextView phone_error, phone_sure, notification3;LinearLayout customer_dialog_warn_linear, customer_dialog_phoneofmessage;MyHandler handler;/** * init the dialog * * @return */public CustomerDialog(Context con,final MyHandler handler) {this.context = con;this.handler = handler;dialog = new Dialog(context, R.style.PersonalInfomationDialog);dialog.setContentView(R.layout.custom_dialog_layout);phone_error = (TextView) dialog.findViewById(R.id.phone_error);phone_sure = (TextView) dialog.findViewById(R.id.phone_sure);notification3 = (TextView) dialog.findViewById(R.id.notification3);sure = (Button) dialog.findViewById(R.id.sure);cancle = (Button) dialog.findViewById(R.id.cancle);DensityUtil.setViewWHForW(context, sure, 150,90);DensityUtil.setViewWHForW(context, cancle, 150,90);customer_dialog_warn_linear = (LinearLayout) dialog.findViewById(R.id.warn_linear);customer_dialog_phoneofmessage = (LinearLayout) dialog.findViewById(R.id.phoneofmessage);sure.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent();//intent.setAction("show_userinfo_verification_code");//// 发出广播 打开验证码页面//context.sendBroadcast(intent); Message msg = new Message(); msg.what = 4; handler.sendMessage(msg);//////Intent intent = new Intent(context,PersonalInfomationActivity.class);////context.startActivity(intent);}});cancle.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {dismiss();}});}/** * @category Set The Content of the Button * */public void setButtonText(String buttontext) {cancle.setText(buttontext);}public void show() {dialog.show();}public void hide() {dialog.hide();}/** * 验证手机 */public void show_phone_sure() {phone_sure.setVisibility(View.VISIBLE);}public void hide_phone_sure() {phone_sure.setVisibility(View.GONE);}/** * 错误 */public void show_phone_error() {phone_error.setVisibility(View.VISIBLE);}public void hide_phone_error() {phone_error.setVisibility(View.GONE);}/** * 手机错误提示层 */public void show_warn_linear() {customer_dialog_warn_linear.setVisibility(View.VISIBLE);}public void hide_warn_linear() {customer_dialog_warn_linear.setVisibility(View.GONE);}/** * 按钮显示隐藏 */public void show_button_ok() {sure.setVisibility(View.VISIBLE);}public void hide_button_ok() {sure.setVisibility(View.GONE);}/** * 短信提示发送层 */public void show_phoneofmessage(String str) {customer_dialog_phoneofmessage.setVisibility(View.VISIBLE);notification3.setText(str);}public void hide_phoneofmessage() {customer_dialog_phoneofmessage.setVisibility(View.GONE);}public void dismiss() {dialog.dismiss();}}在xml倒入dialog
然后在activity中创建
1
MyHandler myHandler = new MyHandler();// 接收事件public class MyHandler extends Handler {public MyHandler(Looper looper) {super(looper);}public MyHandler() {super();}@Overridepublic void handleMessage(Message msg) {Log.v("test", "1");switch (msg.what) {case 4:changeContent(VERIFICATION_CODE);myDialog.dismiss();mid_text.setText(R.string.title_text_content_mid_personalinfomation_verification_code);title_right_text_search.setVisibility(View.GONE);// myDialog.show_phone_sure();// myDialog.hide_phone_error();// myDialog.hide_warn_linear();// myDialog.show_button_ok();// myDialog.show_phoneofmessage(input_phone.getText().toString());Log.v("test", "执行这里");break;case 1:showWhichDialog(SURE_PHONUMER);break;case 2:showWhichDialog(ERROR_PAS);break;default:break;}}};
2
myDialog = new CustomerDialog(PersonalInfomation_Bind_Activity.this,myHandler);
在这里showwhichdialog就是显示dialog.可以显示不同的dialog,
这里我只贴入xml
<?xml version="1.0" encoding="utf-8"?><!-- 自定义的dialog布局 --><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:orientation="vertical" android:padding="30dp" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" > <TextView android:id="@+id/phone_error" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="手机号码错误" android:textColor="@color/title_mid_text_color" android:textSize="@dimen/title_mid_text_size" /> <TextView android:id="@+id/phone_sure" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确认手机号码" android:textColor="@color/title_mid_text_color" android:textSize="@dimen/title_mid_text_size" android:visibility="gone" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:gravity="center" > <LinearLayout android:id="@+id/warn_linear" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="您输入的是一个无效的手机号码" android:textColor="@color/menu_text_loginmode_color" /> </LinearLayout> <LinearLayout android:id="@+id/phoneofmessage" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical" android:visibility="gone" > <TextView android:id="@+id/notification2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我们将发送验证短信到这个号码" /> <TextView android:id="@+id/notification3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="+1861234567" android:textColor="@color/menu_text_username_color" /> </LinearLayout> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:gravity="center" > <Button android:id="@+id/cancle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/menu_text_username_color" android:padding="10dp" android:text="取消" android:textColor="@color/title_right_text_color_normal" /> <Button android:id="@+id/sure" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:background="@color/menu_text_username_color" android:padding="10dp" android:text="确认" android:textColor="@color/title_right_text_color_normal" /> </LinearLayout></LinearLayout>
0 0
- 自定义Dialog android Dialog
- 【Android】Dialog以及自定义Dialog
- android 系统Dialog,自定义Dialog
- android 自定义dialog 自定义dialog 宽度问题
- Android 自定义 dialog
- Android 自定义 dialog
- Android 自定义 dialog
- Android 自定义Dialog分类
- Android Dialog( 自定义对话框)
- Android自定义Dialog
- Android-自定义Dialog样式
- Android 自定义Dialog样式
- Android:自定义dialog
- Android 自定义dialog
- Android自定义Dialog对话框
- Android 自定义dialog
- Android自定义Dialog
- Android自定义Dialog
- 关于使用UDP套接字进行本地进程间…
- linux c控制cpu利用率
- 20130704_TWNIC_Nagios_Ezilla_openSUSE12.2
- UBUNTU下使用ifconfig和route命令…
- 解决最优子结构问题的两种方法----…
- android自定义 dialog
- KMP算法的理解,伪代码,c代码实现
- static变量和extern变量
- 关于头文件,全局变量,extern,st…
- Android 更新UI的两种方法——handler和runOnUiThread()
- C++笔记
- C++复习
- HDU 3782 xxx定律
- 拷贝构造函数 浅拷贝构造函数 深拷…