close
內文以帳號密碼欄作為範例,
AlertDialog可以提供像是Bootstrap的Modal功能。
下面會有例圖幫助理解。
CODE:
帳號密碼部分- 新建一個LinearLayout出來 LinearLayout ll = new LinearLayout(this); Layout的定位, ll.Orientation = Orientation.Vertical; 新建一個可編輯的EditText EditText id = new EditText(this); EditText的HINT,就是圖上灰色的字 id.Hint = "帳號"; 重要的一個地方,將EditText加入LinarLayout裡面 ll.AddView(id); 重複動作不再贅述 EditText pw = new EditText(this); pw.Hint = "密碼"; 讓密碼欄顯示為*****的語法 pw.InputType = Android.Text.InputTypes.TextVariationPassword | Android.Text.InputTypes.ClassText; ll.AddView(pw);
記住帳號密碼的功能,需搭配ISharedPreferences使用 CheckBox cb = new CheckBox(this); ll.AddView(cb); cb.Checked = true; cb.Text = "記住帳號";
AlertDialog 新建AlertDialog出來,有這個才能呈現類似Modal的樣子 AlertDialog.Builder adb = new AlertDialog.Builder(this); 設置AlertDialog的標題 adb.SetTitle("登入"); 將前面新建出來的LinearLayout整個加入AlertDialog adb.SetView(ll); 按鈕的事件: adb.SetPositiveButton("確定",(sender,e)=>{ //do something when agree. }); adb.SetNegativeButton("取消",(sender,e)=>{ //do something when cancel. }); 這個算是最重要的,如果沒有Show()就不會有反應哦! adb.Show();
文章標籤
全站熱搜