系统定义弹窗以及自定义弹窗
来源:互联网 发布:数据山东吧 编辑:程序博客网 时间:2024/06/06 13:18
知识点:
1 系统定义弹窗
2 自定义弹窗
1 系统定义弹窗
android 中系统弹窗可以方便的进行弹窗提醒功能:
使用AlertDialog.Builder Dialog = new AlertDialog.Builder(this);
设置相关属性之后,show()出Dialog即可。
代码:
/** * 展示更新对话框 */protected void ShowDialog() {AlertDialog.Builder Dialog = new AlertDialog.Builder(this);Dialog.setTitle("检查更新");Dialog.setMessage(mDescription);Dialog.setPositiveButton("立即更新", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {DownLoadAPK();}});Dialog.setNegativeButton("以后再说", new OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO Auto-generated method stubEnterHomeActivity();}});Dialog.setOnCancelListener(new OnCancelListener() {@Overridepublic void onCancel(DialogInterface dialog) {EnterHomeActivity();}});Dialog.show();}
2 自定义弹窗:
1 需要编写弹窗xml文件
2 将弹窗xml文件放入到dialog中
step 1:弹窗的xml文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fff" android:orientation="vertical" > <TextView android:id="@+id/tv_dialog_set_passwrod_titile" android:layout_width="match_parent" android:layout_height="30sp" android:background="@android:color/holo_orange_light" android:gravity="center" android:textSize="22sp" android:text="手机防盗" /> <EditText android:id="@+id/et_dialog_set_passwrod_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入密码" android:singleLine="true" > </EditText> <EditText android:id="@+id/et_dialog_set_passwrod_comformpassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入确认密码" android:singleLine="true" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button_dialog_set_passwrod_OK" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="确认" /> <Button android:id="@+id/button_dialog_set_passwrod_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="取消" /> </LinearLayout></LinearLayout>
step2 :将弹窗布局xml文件放入到弹窗中
1 获得dialog,注意在create的时候,进行了类型转换
AlertDialog.Builder builder = new AlertDialog.Builder(HomeActivity.this);final AlertDialog dialog = builder.create();
2 将布局放入
View view=View.inflate(HomeActivity.this, R.layout.dialog_set_password, null);dialog.setView(view, 0, 0, 0, 0);setview(view,0,0,0,0)是为了兼容低版本的androd系统
完整代码:
protected void ShowInputPasswordDialog() {AlertDialog.Builder builder = new AlertDialog.Builder(HomeActivity.this);final AlertDialog dialog = builder.create();View view=View.inflate(HomeActivity.this, R.layout.dialog_set_password, null);final EditText ed_password = (EditText)view.findViewById(R.id.et_dialog_set_passwrod_password);final EditText ed_comformpassword = (EditText)view.findViewById(R.id.et_dialog_set_passwrod_comformpassword);Button Btn_ok = (Button)view.findViewById(R.id.button_dialog_set_passwrod_OK);Button Btn_cancel=(Button)view.findViewById(R.id.button_dialog_set_passwrod_cancel);dialog.setView(view, 0, 0, 0, 0);sharedPreferences = getSharedPreferences("config", MODE_PRIVATE);Btn_ok.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {//获取要放到点击事件内部,在外部会丢掉数据password =ed_password.getText().toString();comformpassword=ed_comformpassword.getText().toString();if(!TextUtils.isEmpty(password)){System.out.println("password : "+password+" comformpassword :" +comformpassword);if(password.equals(comformpassword)){sharedPreferences.edit().putString("password", password).commit();Toast.makeText(HomeActivity.this, "登陆成功", Toast.LENGTH_SHORT).show();dialog.dismiss();}else{Toast.makeText(HomeActivity.this, "登陆失败,请输入两个相同的密码", Toast.LENGTH_SHORT).show();}}}});Btn_cancel.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {dialog.dismiss();}});dialog.show(); }
0 0
- 系统定义弹窗以及自定义弹窗
- 系统exception,以及自定义例外
- 自定义IOS系统弹框
- 利用结构体定义一个加法以及自定义输出
- 自定义C/C++头文件以及重复定义的解决
- WM_USER以及自定义消息WM_XXXX的定义 声明 实现
- PHP系统常量以及自定义常量
- Cocos的动作系统以及自定义Action
- unity自定义宏定义以及常用自带的宏定义
- 各种屏幕尺寸,以及Android的系统定义
- 查询系统已定义OU,ORG 以及相关基本信息
- javascript 自定义弹窗 自定义参数 过渡
- web自动化测试第10步:获取浏览器弹窗alert、自定义弹窗以及其操作
- UINavigationController 自定义弹窗
- iOS 自定义弹窗
- 自定义弹窗
- 自定义弹窗
- 自定义弹窗(uialertview)
- udev用法
- 20个命令行工具监控 Linux 系统性能
- 解除svn版本控制
- 状态栏(UITabBar)、导航栏(UINavigation)
- java继承小实例
- 系统定义弹窗以及自定义弹窗
- Websocket(3)--实时推送
- vector push_back报错 是其他地方内存越界覆盖掉了后面的内存
- No JNI_OnLoad found in ......, skipping init
- js实现百度动态LOGO
- PAT--1085 Perfect Sequence(二分查找)
- ios开发动画效果的基本学习介绍
- 【Java】换底公式
- 数据持久化