Android編程實現(xiàn)打勾顯示輸入密碼功能
本文實例講述了Android編程實現(xiàn)打勾顯示輸入密碼功能。分享給大家供大家參考,具體如下:
main.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="textPassword" android:id="@+id/mima" /> <CheckBox android:text="顯示密碼" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/xianshifou"/> </LinearLayout>
Java代碼:
public class M extends Activity {
private EditText et;
private CheckBox cb;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et=(EditText)findViewById(R.id.mima);
cb=(CheckBox)findViewById(R.id.xianshifou);
cb.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
if(cb.isChecked()){
//設置EditText的密碼為可見的
et.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}else{
//設置密碼為隱藏的
et.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
});
}
}
更多關于Android相關內(nèi)容感興趣的讀者可查看本站專題:《Android視圖View技巧總結》、《Android開發(fā)動畫技巧匯總》、《Android編程之a(chǎn)ctivity操作技巧總結》、《Android布局layout技巧總結》、《Android開發(fā)入門與進階教程》、《Android資源操作技巧匯總》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
相關文章
Android studio 引用aar 進行java開發(fā)的操作步驟
這篇文章主要介紹了Android studio 引用aar 進行java開發(fā)的操作步驟,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-09-09
Android中系統(tǒng)自帶鎖WalkLock與KeyguardLock用法實例詳解
這篇文章主要介紹了Android中系統(tǒng)自帶鎖WalkLock與KeyguardLock用法,結合實例形式較為詳細的分析了WalkLock與KeyguardLock的功能、作用、使用方法與相關注意事項,需要的朋友可以參考下2016-01-01
Android應用開發(fā)SharedPreferences存儲數(shù)據(jù)的使用方法
SharedPreferences是Android中最容易理解的數(shù)據(jù)存儲技術,實際上SharedPreferences處理的就是一個key-value(鍵值對)SharedPreferences常用來存儲一些輕量級的數(shù)據(jù)2012-11-11
Android瀑布流照片墻實現(xiàn) 體驗不規(guī)則排列的美感
這篇文章主要為大家詳細介紹了Android瀑布流照片墻實現(xiàn),體驗不規(guī)則排列的美感,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10

