Android 自定義對話框 showSetPwdDialog
更新時間:2016年03月29日 09:13:50 作者:榮雪---rongsnow
這篇文章主要介紹了Android 自定義對話框 showSetPwdDialog的相關(guān)資料,需要的朋友可以參考下
樣式如下所示:
布局:
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" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#EFEFEF" android:orientation="horizontal" android:padding="dp" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/dialog_title_default_icon" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="dp" android:text="設(shè)置密碼" android:textColor="@color/black" android:textSize="sp" /> </LinearLayout> <EditText android:id="@+id/et_pwd" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="dp" android:hint="請輸入密碼" android:inputType="textPassword" > </EditText> <EditText android:id="@+id/et_pwd_confirm" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="dp" android:hint="請再次輸入密碼" android:inputType="textPassword" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="dp" > <Button android: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" /> <Button android: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>
狀態(tài)選擇器:
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);//將當(dāng)前布局對象設(shè)置給dialog final AlertDialog dialog = builder.create(); btnOk.setOnClickListener(new OnClickListener() { @Override public 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(), "輸入內(nèi)容不能為空!"); } else { if (pwd.equals(pwdConfirm)) { System.out.println("登錄成功!"); //將密碼保存在本地sp PrefUtils.putString(getApplicationContext(), GlobalConstants.PREF_PASSWORD, MDUtils.getMd(pwd)); dialog.dismiss(); enterLostAndFindPage(); } else { ToastUtils.showToast(getApplicationContext(), "兩次密碼不一致!"); } } } }); btnCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); }
有關(guān)Android 自定義對話框 showSetPwdDialog,小編就給大家介紹這么多,希望對大家有所幫助!
您可能感興趣的文章:
- Android中自定義對話框(Dialog)的實例代碼
- Android使用setCustomTitle()方法自定義對話框標(biāo)題
- ANDROID中自定義對話框AlertDialog使用示例
- Android常用的AlertDialog對話框及自定義對話框
- Android自定義對話框Dialog的簡單實現(xiàn)
- Android 根據(jù)EditText搜索框ListView動態(tài)顯示數(shù)據(jù)
- Android控件系列之EditText使用方法
- Android中實現(xiàn)EditText圓角的方法
- Android EditText常用屬性功能匯總
- Android EditText自定義樣式的方法
- Android編程實現(xiàn)在自定義對話框中獲取EditText中數(shù)據(jù)的方法
相關(guān)文章
Android實現(xiàn)動態(tài)自動匹配輸入內(nèi)容功能
這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)動態(tài)自動匹配輸入內(nèi)容功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06android 監(jiān)聽SD卡文件變化的實現(xiàn)代碼
這篇文章主要介紹了android 監(jiān)聽SD卡文件變化的實現(xiàn)代碼,需要的朋友可以參考下2017-11-11