Android 帶password輸入介面的Dialog實現機制

來源:互聯網
上載者:User

標籤:

1.布局實現:

<?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:gravity="center_horizontal"    android:orientation="vertical">    <EditText        android:id="@+id/FactRstDialogPsw"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:password="true"        android:singleLine="true"/>    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal"        android:layout_weight="2">        <Button            android:id="@+id/FactRstDialogCancel"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center_horizontal"            android:text="@string/cancel"            android:layout_weight="1"/>        <Button            android:id="@+id/FactRstDialogCertain"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center_horizontal"            android:text="@string/user_dict_settings_add_dialog_confirm"            android:layout_weight="1"/></LinearLayout></LinearLayout>


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.addprivate 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(){@Overridepublic void onClick(View source){mFactRstPwsCheckDialog.dismiss();//finish();}});okButton.setOnClickListener(new View.OnClickListener(){@Overridepublic 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 activitymFactRstPwsCheckDialog.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}




Android 帶password輸入介面的Dialog實現機制

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.