Android 自定義對(duì)話框 showSetPwdDialog
樣式如下所示:
布局:
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="請(qǐng)輸入密碼" 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="請(qǐng)?jiān)俅屋斎朊艽a" 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)前布局對(duì)象設(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 自定義對(duì)話框 showSetPwdDialog,小編就給大家介紹這么多,希望對(duì)大家有所幫助!
- Android中自定義對(duì)話框(Dialog)的實(shí)例代碼
- Android使用setCustomTitle()方法自定義對(duì)話框標(biāo)題
- ANDROID中自定義對(duì)話框AlertDialog使用示例
- Android常用的AlertDialog對(duì)話框及自定義對(duì)話框
- Android自定義對(duì)話框Dialog的簡(jiǎn)單實(shí)現(xiàn)
- Android 根據(jù)EditText搜索框ListView動(dòng)態(tài)顯示數(shù)據(jù)
- Android控件系列之EditText使用方法
- Android中實(shí)現(xiàn)EditText圓角的方法
- Android EditText常用屬性功能匯總
- Android EditText自定義樣式的方法
- Android編程實(shí)現(xiàn)在自定義對(duì)話框中獲取EditText中數(shù)據(jù)的方法
相關(guān)文章
Android自定義View實(shí)現(xiàn)心形圖案
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)心形圖案,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09Android提高之模擬信號(hào)示波器的實(shí)現(xiàn)
這篇文章主要介紹了Android模擬信號(hào)示波器的實(shí)現(xiàn)方法,在Android項(xiàng)目開(kāi)發(fā)中有一定的實(shí)用價(jià)值,需要的朋友可以參考下2014-08-08Flutter實(shí)現(xiàn)仿京東商品詳情底部操作欄
這篇文章主要為大家詳細(xì)介紹了Flutter如何仿京東實(shí)現(xiàn)商品詳情底部操作欄,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以了解一下2023-06-06Android 軟鍵盤自動(dòng)彈出與關(guān)閉實(shí)例詳解
這篇文章主要介紹了Android 軟鍵盤自動(dòng)彈出與關(guān)閉實(shí)例詳解的相關(guān)資料,為了用戶體驗(yàn)應(yīng)該自動(dòng)彈出軟鍵盤而不是讓用戶主動(dòng)點(diǎn)擊輸入框才彈出,這里舉例說(shuō)明該如何實(shí)現(xiàn),需要的朋友可以參考下2016-12-12Android 使用幀動(dòng)畫內(nèi)存溢出解決方案
這篇文章主要介紹了Android 使用幀動(dòng)畫內(nèi)存溢出解決方案的相關(guān)資料,這里提供了詳細(xì)的解決辦法,具有參考價(jià)值,需要的朋友可以參考下2016-12-12Android實(shí)現(xiàn)動(dòng)態(tài)自動(dòng)匹配輸入內(nèi)容功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)動(dòng)態(tài)自動(dòng)匹配輸入內(nèi)容功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06Android開(kāi)發(fā)之Location用法實(shí)例分析
這篇文章主要介紹了Android開(kāi)發(fā)中Location用法,結(jié)合實(shí)例形式分析了Android使用location控件獲取經(jīng)緯度信息的相關(guān)操作技巧,需要的朋友可以參考下2016-10-10android 監(jiān)聽(tīng)SD卡文件變化的實(shí)現(xiàn)代碼
這篇文章主要介紹了android 監(jiān)聽(tīng)SD卡文件變化的實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-11-11Android編程實(shí)現(xiàn)隨機(jī)生成顏色的方法示例
這篇文章主要介紹了Android編程實(shí)現(xiàn)隨機(jī)生成顏色的方法,結(jié)合實(shí)例形式分析了Android使用java Random類針對(duì)隨機(jī)數(shù)及顏色值相關(guān)操作技巧,需要的朋友可以參考下2017-08-08