Android 自訂對話方塊 showSetPwdDialog_Android

來源:互聯網
上載者:User

樣式如下所示:

布局:

layout

  dialog_set_pwd.xml

<?xml version="." encoding="utf-"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:background="#EFEFEF"android:orientation="horizontal"android:padding="dp" ><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@drawable/dialog_title_default_icon" /><TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="dp"android:text="設定密碼"android:textColor="@color/black"android:textSize="sp" /></LinearLayout><EditTextandroid:id="@+id/et_pwd"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="dp"android:hint="請輸入密碼"android:inputType="textPassword" ></EditText><EditTextandroid:id="@+id/et_pwd_confirm"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="dp"android:hint="請再次輸入密碼"android:inputType="textPassword" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:padding="dp" ><Buttonandroid:id="@+id/btn_ok"android:layout_width="dp"android:layout_height="wrap_content"android:layout_weight=""android:background="@drawable/btn_blue_selector"android:text="確定"android:layout_marginRight="dp"android:textColor="@color/white" /><Buttonandroid:id="@+id/btn_cancel"android:layout_width="dp"android:layout_height="wrap_content"android:layout_weight=""android:background="@drawable/btn_white_selector"android:text="取消"android:textColor="@color/black" /></LinearLayout></LinearLayout>

狀態選取器:

drawable

  btn_blue_selector.xml

<?xml version="." encoding="utf-"?><selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/dg_btn_confirm_select" android:state_pressed="true"></item><item android:drawable="@drawable/dg_btn_confirm_normal"></item></selector>

  btn_white_selector.xml

<?xml version="." encoding="utf-"?><selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/dg_button_cancel_select" android:state_pressed="true"></item><item android:drawable="@drawable/dg_button_cancel_normal"></item></selector>

引用值

values

  colors.xml

<?xml version="." encoding="utf-"?><resources><color name="black">#</color><color name="gray">#a</color><color name="white">#fff</color><color name="red">#f</color><color name="shape_setting_normal">#BDEE</color><color name="shape_setting_pressed">#CAD</color><color name="blue">#FD</color><color name="light_green">#f</color></resources> 

代碼:

private void showSetPwdDialog() {AlertDialog.Builder builder = new AlertDialog.Builder(this);View view = View.inflate(this, R.layout.dialog_set_pwd, null);Button btnOk = (Button) view.findViewById(R.id.btn_ok);Button btnCancel = (Button) view.findViewById(R.id.btn_cancel);final EditText etPwd = (EditText) view.findViewById(R.id.et_pwd);final EditText etPwdConfirm = (EditText) view.findViewById(R.id.et_pwd_confirm);builder.setView(view);//將當前布局對象設定給dialogfinal AlertDialog dialog = builder.create();btnOk.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {String pwd = etPwd.getText().toString().trim();String pwdConfirm = etPwdConfirm.getText().toString().trim();if (TextUtils.isEmpty(pwd) || TextUtils.isEmpty(pwdConfirm)) {ToastUtils.showToast(getApplicationContext(), "輸入內容不可為空!");} else {if (pwd.equals(pwdConfirm)) {System.out.println("登入成功!");//將密碼儲存在本地spPrefUtils.putString(getApplicationContext(),GlobalConstants.PREF_PASSWORD,MDUtils.getMd(pwd));dialog.dismiss();enterLostAndFindPage();} else {ToastUtils.showToast(getApplicationContext(),"兩次密碼不一致!");}}}});btnCancel.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {dialog.dismiss();}});dialog.show();}

有關Android 自訂對話方塊 showSetPwdDialog,小編就給大家介紹這麼多,希望對大家有所協助!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.