标签:iss back textutils layout cte mobile bsp dialog override
protected void showDialog() { //判断本地是否有存储密码(sp 字符串) String psd = SpUtil.getString(this, ConstantValue.MOBILE_SAFE_PSD, ""); if(TextUtils.isEmpty(psd)){ //1,初始设置密码对话框 showSetPsdDialog(); }else{ //2,确认密码对话框 showConfirmPsdDialog(); } } /** * 确认密码对话框 */ private void showConfirmPsdDialog() { //因为需要去自己定义对话框的展示样式,所以需要调用dialog.setView(view); //view是由自己编写的xml转换成的view对象xml----->view Builder builder = new AlertDialog.Builder(this); final AlertDialog dialog = builder.create(); final View view = View.inflate(this, R.layout.dialog_confirm_psd, null); //让对话框显示一个自己定义的对话框界面效果 dialog.setView(view); dialog.show(); Button bt_submit = (Button) view.findViewById(R.id.bt_submit); Button bt_cancel = (Button) view.findViewById(R.id.bt_cancel); bt_submit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText et_confirm_psd = (EditText)view.findViewById(R.id.et_confirm_psd); String confirmPsd = et_confirm_psd.getText().toString(); if(!TextUtils.isEmpty(confirmPsd)){ String psd = SpUtil.getString(getApplicationContext(), ConstantValue.MOBILE_SAFE_PSD, ""); if(psd.equals(confirmPsd)){ //进入应用手机防盗模块,开启一个新的activity Intent intent = new Intent(getApplicationContext(), TestActivity.class); startActivity(intent); //跳转到新的界面以后需要去隐藏对话框 dialog.dismiss(); }else{ ToastUtil.show(getApplicationContext(),"确认密码错误"); } }else{ //提示用户密码输入有为空的情况 ToastUtil.show(getApplicationContext(), "请输入密码"); } } }); bt_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); } /** * 设置密码对话框 */ private void showSetPsdDialog() { //因为需要去自己定义对话框的展示样式,所以需要调用dialog.setView(view); //view是由自己编写的xml转换成的view对象xml----->view Builder builder = new AlertDialog.Builder(this); final AlertDialog dialog = builder.create(); final View view = View.inflate(this, R.layout.dialog_set_psd, null); //让对话框显示一个自己定义的对话框界面效果 dialog.setView(view); dialog.show(); Button bt_submit = (Button) view.findViewById(R.id.bt_submit); Button bt_cancel = (Button) view.findViewById(R.id.bt_cancel); bt_submit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText et_set_psd = (EditText) view.findViewById(R.id.et_set_psd); EditText et_confirm_psd = (EditText)view.findViewById(R.id.et_confirm_psd); String psd = et_set_psd.getText().toString(); String confirmPsd = et_confirm_psd.getText().toString(); if(!TextUtils.isEmpty(psd) && !TextUtils.isEmpty(confirmPsd)){ if(psd.equals(confirmPsd)){ //进入应用手机防盗模块,开启一个新的activity Intent intent = new Intent(getApplicationContext(), TestActivity.class); startActivity(intent); //跳转到新的界面以后需要去隐藏对话框 dialog.dismiss(); SpUtil.putString(getApplicationContext(), ConstantValue.MOBILE_SAFE_PSD, psd); }else{ ToastUtil.show(getApplicationContext(),"确认密码错误"); } }else{ //提示用户密码输入有为空的情况 ToastUtil.show(getApplicationContext(), "请输入密码"); } } }); bt_cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); }
/res/layout/dialog_confirm_psd.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:orientation="vertical" > <TextView style="@style/TitleStyle" android:text="确认密码" android:background="#f30"/> <!-- android:hint=""提示用户输入内容 --> <EditText android:id="@+id/et_confirm_psd" android:hint="确认密码" android:inputType="textPassword" android:layout_width="match_parent" android:layout_height="wrap_content"/> <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_weight="1" android:layout_height="wrap_content"/> <Button android:text="取消" android:id="@+id/bt_cancel" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"/> </LinearLayout> </LinearLayout>
/res/layout/dialog_set_psd.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:orientation="vertical" > <TextView style="@style/TitleStyle" android:text="设置密码" android:background="#f30"/> <!-- android:hint=""提示用户输入内容 --> <EditText android:id="@+id/et_set_psd" android:hint="设置密码" android:inputType="textPassword" android:layout_width="match_parent" android:layout_height="wrap_content"/> <EditText android:id="@+id/et_confirm_psd" android:hint="确认密码" android:inputType="textPassword" android:layout_width="match_parent" android:layout_height="wrap_content"/> <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_weight="1" android:layout_height="wrap_content"/> <Button android:text="取消" android:id="@+id/bt_cancel" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"/> </LinearLayout> </LinearLayout>
标签:iss back textutils layout cte mobile bsp dialog override
原文地址:http://www.cnblogs.com/xufengyuan/p/6238186.html