国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Dialog對(duì)話框使用小結(jié),讓你多點(diǎn)時(shí)間陪妹子

2019-11-09 14:17:52
字體:
供稿:網(wǎng)友

花了一個(gè)小時(shí)對(duì)Dialog對(duì)話框使用小結(jié)一下,比較基礎(chǔ),希望對(duì)你學(xué)習(xí)有幫助,大牛請(qǐng)直接關(guān)閉網(wǎng)頁。如果你是新手,建議你親自敲一遍代碼。

先看一下效果:

Dialog對(duì)話框使用小結(jié)

1. 普通對(duì)話框

AlertDialog.Builder builder = new AlertDialog.Builder(activity);builder.setTitle("溫馨提示");//標(biāo)題builder.setMessage("天氣冷,注意保暖");builder.setIcon(R.mipmap.ic_launcher);builder.create();builder.show();

普通對(duì)話框

2. 確定取消對(duì)話框

builder.setTitle("確定取消對(duì)話框");builder.setMessage("請(qǐng)選擇確定或取消");builder.setIcon(R.mipmap.ic_launcher);builder.setPositiveButton("確定", new DialogInterface.OnClickListener() { //正能量按鈕 Positive @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(activity, "你點(diǎn)擊了確定", Toast.LENGTH_SHORT).show(); }});builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(activity, "你選擇了取消", Toast.LENGTH_SHORT).show(); }});builder.create().show();

確定取消對(duì)話框

3. 多按鈕對(duì)話框

builder.setTitle("多個(gè)按鈕對(duì)話框");builder.setMessage("請(qǐng)選擇");builder.setIcon(R.mipmap.ic_launcher);builder.setPositiveButton("我沒玩夠", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(activity, "繼續(xù)瀏覽精彩內(nèi)容", Toast.LENGTH_SHORT).show(); }});builder.setNeutralButton("開啟", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(activity, "起床了", Toast.LENGTH_SHORT).show(); }});builder.setNegativeButton("我累了,要休息一下", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(activity, "歡迎再來", Toast.LENGTH_SHORT).show(); }});builder.create().show();

多按鈕對(duì)話框

4. 列表對(duì)話框

final String arrItem[] = getResources().getStringArray(R.array.aikaifa);builder.setItems(arrItem, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(activity, "你選擇了第" + arrItem[which], Toast.LENGTH_SHORT).show(); }});builder.create().show();

列表對(duì)話框

5. 帶Adapter的對(duì)話框

builder.setTitle("帶Adapter的對(duì)話框");builder.setIcon(R.mipmap.ic_launcher);final List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();int arrImg[] = {R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher};for (int i = 0; i < arrImg.length; i++) { Map<String, Object> map = new HashMap<String, Object>(); map.put("img", arrImg[i]); map.put("title", "愛開發(fā)" + i); list.add(map);}SimpleAdapter adapter = new SimpleAdapter(activity, list, R.layout.list_item, new String[]{"img", "title"}, new int[]{R.id.iv, R.id.tv});builder.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(activity, "你選擇了" + list.get(which).get("title").toString().trim(), Toast.LENGTH_SHORT).show(); }});builder.create().show();

帶Adapter的對(duì)話框

6. 單選對(duì)話框

builder.setTitle("單選對(duì)話框");builder.setIcon(R.mipmap.ic_launcher);builder.setSingleChoiceItems(R.array.aikaifa, 0, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(activity, which+"", Toast.LENGTH_SHORT).show(); }});builder.setPositiveButton("確定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { }});builder.create().show();

單選對(duì)話框

7. 多選對(duì)話框

builder.setTitle("多選對(duì)話框");builder.setIcon(R.mipmap.ic_launcher);builder.setMultiChoiceItems(R.array.aikaifa, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { Toast.makeText(activity, which+""+isChecked, Toast.LENGTH_SHORT).show(); }});builder.create().show();

多選對(duì)話框

8. 日期對(duì)話框

DatePickerDialog datePickerDialog=new DatePickerDialog(activity, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {Toast.makeText(activity, year+"年"+(monthOfYear+1)+"月"+dayOfMonth+"日", Toast.LENGTH_SHORT).show(); } }, 2017, 02, 9);datePickerDialog.show();

日期對(duì)話框

9. 時(shí)間對(duì)話框

TimePickerDialog timePickerDialog=new TimePickerDialog(activity, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) {Toast.makeText(activity, hourOfDay+"小時(shí)"+minute+"分鐘", Toast.LENGTH_SHORT).show(); } }, 17, 49, true);timePickerDialog.show();

時(shí)間對(duì)話框

10. 自定義對(duì)話框

View view= LayoutInflater.from(activity).inflate(R.layout.dialog_login, null);builder.setView(view);builder.create();final EditText et_phone=(EditText)view.findViewById(R.id.et_phone);final EditText et_passWord=(EditText)view.findViewById(R.id.et_password);Button btn_submit=(Button)view.findViewById(R.id.btn_submit);btn_submit.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(activity, "手機(jī)號(hào)碼:"+et_phone.getText().toString()+" 短信驗(yàn)證碼:"+et_password.getText().toString(), Toast.LENGTH_SHORT).show(); }});builder.show();

自定義對(duì)話框

項(xiàng)目設(shè)計(jì)到的xml

list_item.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#f5f5f5" android:orientation="horizontal" android:padding="10dp"> <ImageView android:id="@+id/iv" android:src="@mipmap/ic_launcher" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/tv" android:text="標(biāo)題" android:layout_width="wrap_content" android:layout_height="wrap_content" /></LinearLayout>

dialog_login.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:orientation="vertical"> <LinearLayout android:id="@+id/linearLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_margin="8dp" android:orientation="vertical" android:padding="5dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginTop="10dp" android:gravity="center_horizontal" android:text="驗(yàn)證手機(jī)號(hào)碼" android:textColor="#414141" /> <EditText android:id="@+id/et_phone" android:layout_width="match_parent" android:layout_height="48dp" android:gravity="center_vertical" android:hint="請(qǐng)輸入手機(jī)號(hào)碼" android:inputType="number" android:maxLength="11" android:paddingLeft="10dp" android:textSize="14sp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="20dp" android:layout_marginTop="10dp"> <EditText android:id="@+id/et_password" android:layout_width="0dp" android:layout_height="48dp" android:layout_weight="4" android:gravity="center_vertical" android:hint="請(qǐng)輸入短信驗(yàn)證碼" android:inputType="number" android:maxLength="6" android:paddingLeft="10dp" android:textSize="14sp" /> <TextView android:id="@+id/tv_get_code" android:layout_width="0dp" android:layout_height="48dp" android:layout_marginLeft="10dp" android:layout_weight="2" android:enabled="false" android:gravity="center" android:text="點(diǎn)擊獲取" android:textColor="#000000" /> </LinearLayout> <Button android:id="@+id/btn_submit" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#000000" android:gravity="center" android:paddingBottom="10dp" android:paddingTop="10dp" android:text="提交" /> </LinearLayout></RelativeLayout>

源碼下載

[END]

感興趣掃描一下二維碼關(guān)注一下,或搜索公眾號(hào) aikaifa 微信公眾號(hào)aikaifa

愛開發(fā)致力于成為中國(guó)創(chuàng)業(yè)者的信息平臺(tái)和服務(wù)平臺(tái),幫助開發(fā)者實(shí)現(xiàn)創(chuàng)業(yè)夢(mèng)想。愛開發(fā)為開發(fā)者提供各種創(chuàng)業(yè)類最新資訊和實(shí)用知識(shí)手冊(cè),打造為開發(fā)者提供高價(jià)值的信息平臺(tái)。


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大洼县| 通河县| 务川| 马关县| 岢岚县| 呼伦贝尔市| 甘谷县| 龙南县| 固镇县| 抚顺县| 陆良县| 万安县| 巫山县| 沙田区| 沙河市| 石狮市| 方城县| 夹江县| 余江县| 兴和县| 马关县| 潮安县| 常熟市| 中卫市| 松阳县| 调兵山市| 绥芬河市| 张北县| 修水县| 阳江市| 屏东县| 林甸县| 凤冈县| 都江堰市| 时尚| 阜新| 长泰县| 曲周县| 吴旗县| 鸡西市| 常宁市|