1.布局实现:
2.代码实现:
import android.app.Dialog;import android.content.Context;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import com.mediatek.common.featureoption.FeatureOption; public class MasterClearConfirm extends Fragment { //cbk.add private Dialog mFactRstPwsCheckDialog; private Button cancelButton; private Button okButton; private EditText pswEdit; //cbk.add private Button.OnClickListener mFinalClickListener = new Button.OnClickListener() { public void onClick(View v) { if (Utils.isMonkeyRunning()) { return; } /// M:For CT feature resetPhone with mEraseInternalData: data | app | media //cbk.add //mExt.onResetPhone(getActivity(), mEraseInternalData, mEraseSdCard); createFactoryResetPwdDialog(); //cbk.add } };//cbk.add private void createFactoryResetPwdDialog() { if (mFactRstPwsCheckDialog == null) { mFactRstPwsCheckDialog = new Dialog(getActivity()); //mFactRstPwsCheckDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); mFactRstPwsCheckDialog.setContentView(R.layout.factory_rst_pwd_dialog); mFactRstPwsCheckDialog.setTitle("please input password:"); pswEdit = (EditText)mFactRstPwsCheckDialog.findViewById(R.id.FactRstDialogPsw); cancelButton = (Button)mFactRstPwsCheckDialog.findViewById(R.id.FactRstDialogCancel); okButton = (Button)mFactRstPwsCheckDialog.findViewById(R.id.FactRstDialogCertain); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View source) { mFactRstPwsCheckDialog.dismiss();//finish(); } }); okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View source) { onPairPassword(pswEdit.getText().toString()); pswEdit.setText(null); } }); } if (mFactRstPwsCheckDialog != null) { mFactRstPwsCheckDialog.show(); } } private boolean onPairPassword(String value){ //Log.d(TAG, "onPairPassword() pwd value=" +value); boolean pwdvalid=false; if(value ==null ){ //Log.d(TAG, "onPairPassword() value ==null"); Toast.makeText(getActivity(), getString(R.string.settings_pwd_empty_str), Toast.LENGTH_SHORT).show(); return false; } if(value.length()<=0 ){ //Log.d(TAG, "onPairPassword() value ==null"); Toast.makeText(getActivity(), getString(R.string.settings_pwd_empty_str), Toast.LENGTH_SHORT).show(); return false; } String def_pwd_value =getString(R.string.settings_pwd_def); //if(value.length() !=6 || isNumeric(value) ==false){ if(value.length() < def_pwd_value.length()){ //add the item into the Locked list. //Log.d(TAG, "onPairPassword() value ==valid"); Toast.makeText(getActivity(), getString(R.string.settings_pwd_wrong_str), Toast.LENGTH_SHORT).show(); return false; } //Log.d(TAG, "onPairPassword() pwd_length =" +value.length() ); if (value.equals(def_pwd_value)) { //add the item into the Locked list. //Log.d(TAG, "onPairPassword() mPref.contains(PWD_PREF_NAME) ==true"); //no store the pwd activity mFactRstPwsCheckDialog.dismiss();//finish(); mExt.onResetPhone(getActivity(), mEraseInternalData, mEraseSdCard); return true; } Toast.makeText(getActivity(), getString(R.string.settings_pwd_wrong_str), Toast.LENGTH_SHORT).show(); return false; } //cbk.add }