CommonDialog
来源:互联网 发布:gps静态漂移过滤算法 编辑:程序博客网 时间:2024/05/18 00:51
在实际的开发当中,我们APP项目中的各种提示框都是统一的。为了避免重复的代码和样式的不同,所以我们需要定义一个统一样式的提示框!代码示例如下:
package com.wly.home.widget;import com.wanbu.dascom.R;import android.app.Dialog;import android.content.Context;import android.text.Editable;import android.text.TextWatcher;import android.view.View;import android.widget.EditText;import android.widget.TextView;/** * 统一样式的Dialog * @author wangly * */public class CommonDialog extends Dialog implements android.view.View.OnClickListener { private TextView tv_title; private TextView tv_info; private EditText et_inputInfo; private TextView tv_number; private TextView tv_cancle; private TextView tv_ok; private CallBackListener listener; public void setListener(CallBackListener listener) { this.listener = listener; } public CommonDialog(Context context) { super(context,R.style.commonDialog_style); intView(); } private void intView() { setContentView(R.layout.common_layout_dialog); tv_title = (TextView) findViewById(R.id.tv_title); tv_info = (TextView) findViewById(R.id.tv_info); et_inputInfo = (EditText) findViewById(R.id.et_inputInfo); et_inputInfo.addTextChangedListener(watcher); tv_number = (TextView) findViewById(R.id.tv_number); tv_cancle = (TextView) findViewById(R.id.tv_cancle); tv_ok = (TextView) findViewById(R.id.tv_ok); tv_cancle.setOnClickListener(this); tv_ok.setOnClickListener(this); } /** * 设置标题 * @param text * @param flag 显示/隐藏 */ public void setTiltle(String text,int flag){ tv_title.setText(text); tv_title.setVisibility(flag); } /** * 设置Dialog描述信息 * @param text * @param flag 显示/隐藏 */ public void setInfo(String text,int flag){ tv_info.setText(text); tv_info.setVisibility(flag); } /** * 设置 "取消" 按钮文字 * @param text */ public void setCancleText(String text){ tv_cancle.setText(text); } /** * 设置 "确定" 按钮文字 * @param text */ public void setConfirmText(String text){ tv_ok.setText(text); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.tv_cancle: if (listener!=null) { listener.cancleListener(); } break; case R.id.tv_ok: if (listener!=null) { listener.confirmListener(et_inputInfo.getText().toString().trim()); } break; default: break; } } /** * EditText 字符控制 */ int num = 100;//限制的最大字数 TextWatcher watcher =new TextWatcher(){ private CharSequence temp; private int selectionStart; private int selectionEnd; @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { temp = s; } @Override public void afterTextChanged(Editable s) { int number = num - s.length(); tv_number.setText(s.length()+"/100"); selectionStart = et_inputInfo.getSelectionStart(); selectionEnd = et_inputInfo.getSelectionEnd(); if (temp.length() > num) { s.delete(selectionStart - 1, selectionEnd); int tempSelection = selectionEnd; et_inputInfo.setText(s); et_inputInfo.setSelection(tempSelection);//设置光标在最后 } } }; public interface CallBackListener{ /** * 取消 */ void cancleListener(); /** * 确定 * 获取EditText 输入的内容 */ void confirmListener(String text); }}<style name="commonDialog_style" parent="@android:Theme.Dialog"> <item name="android:windowNoTitle">true</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowBackground">@drawable/update_dialog_shape</item> </style>
1 0
- CommonDialog
- CommonDialog
- CommonDialog
- VB中CommonDialog示例
- VB中CommonDialog示例
- 通用对话弹窗CommonDialog
- Visual Basic CommonDialog 控件的使用
- vb CommonDialog printer 的flags设置
- Visual Basic CommonDialog 控件的使用
- Visual Basic CommonDialog 控件的使用
- vb的CommonDialog控件的使用
- commonDialog引发AccessViolationException的一种原因
- [转载]VB中CommonDialog控件的使用
- vb commondialog 如何设置初始化路径啊?
- VB的CommonDialog控件的使用
- 可以自定义布局的对话框---CommonDialog
- 用CommonDialog公共对话框选取多个文件
- CommonDialog中同时打开多个文件实现(转)
- 设计模式
- java中null与空字符串的区别
- C++第3次作业
- 第三章 面向对象
- Struts2相关概念(很全)---以下是个人总结,未经博主允许不得转载
- CommonDialog
- c++第三次作业
- 动态库dll加载
- Ajax使用介绍
- LeetCode112—Path Sum
- Objective-c MRC内存管理-野指针
- VMware虚拟机设置(vmtools&分辨率)
- [深入浅出Cocoa]详解键值观察(KVO)及其实现机理
- java内存分配分析/栈内存、堆内存