Android普通對(duì)話框用法實(shí)例分析
本文實(shí)例講述了Android普通對(duì)話框用法。分享給大家供大家參考。具體如下:
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"> <EditText android:text="" android:id="@+id/editText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:editable="false" android:cursorVisible="false" /> <Button android:text="顯示普通對(duì)話框" android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
AlertDialog類:
package com.ljq.dialog;
import android.app.Activity;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class AlertDialog extends Activity {
private EditText editText;
private final static int DIALOG=1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText=(EditText)findViewById(R.id.editText);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// 顯示對(duì)話框
showDialog(DIALOG);
}
});
}
/**
* 創(chuàng)建普通對(duì)話框
*/
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog=null;
switch (id) {
case DIALOG:
Builder builder=new android.app.AlertDialog.Builder(this);
//設(shè)置對(duì)話框的圖標(biāo)
builder.setIcon(R.drawable.header);
//設(shè)置對(duì)話框的標(biāo)題
builder.setTitle("普通對(duì)話框");
//設(shè)置對(duì)話框的顯示內(nèi)容
builder.setMessage("這是普通對(duì)話框中的內(nèi)容!!");
//添加按鈕,android.content.DialogInterface.OnClickListener.OnClickListener
builder.setPositiveButton(" 確 定 ", new OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
editText.setText("這是普通對(duì)話框中的內(nèi)容?。?);
}
});
//創(chuàng)建一個(gè)普通對(duì)話框
dialog=builder.create();
break;
}
return dialog;
}
}
運(yùn)行結(jié)果:

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。
- Android之復(fù)選框?qū)υ捒蛴梅▽?shí)例分析
- Android列表對(duì)話框用法實(shí)例分析
- Android單選按鈕對(duì)話框用法實(shí)例分析
- Android之日期及時(shí)間選擇對(duì)話框用法實(shí)例分析
- android幾種不同對(duì)話框的實(shí)現(xiàn)方式
- Android開發(fā)必知 九種對(duì)話框的實(shí)現(xiàn)方法
- Android實(shí)現(xiàn)點(diǎn)擊AlertDialog上按鈕時(shí)不關(guān)閉對(duì)話框的方法
- Android中創(chuàng)建一個(gè)透明的進(jìn)度對(duì)話框?qū)嵗?/a>
- Android復(fù)選框?qū)υ捒蛴梅▽?shí)例簡(jiǎn)析
相關(guān)文章
Jenkins打包android應(yīng)用時(shí)自動(dòng)簽名apk詳解
這篇文章主要介紹了Jenkins打包android應(yīng)用時(shí)自動(dòng)簽名apk詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-07-07
android輕量級(jí)無侵入式管理數(shù)據(jù)庫自動(dòng)升級(jí)組件
這篇文章主要為大家介紹了android輕量級(jí)無侵入式管理數(shù)據(jù)庫自動(dòng)升級(jí)組件詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
OpenHarmony如何調(diào)用電話服務(wù)API撥打電話
OpenHarmony3.1版本標(biāo)準(zhǔn)系統(tǒng)增加了通話相關(guān)的聯(lián)系人應(yīng)用,來電應(yīng)用等,在系統(tǒng)服務(wù)層面電話相關(guān)功能也比較完善,這篇文章主要介紹了OpenHarmony如何調(diào)用電話服務(wù)API撥打電話2022-11-11
Android PC投屏功能實(shí)現(xiàn)的示例代碼
本篇文章主要介紹了Android PC投屏功能實(shí)現(xiàn)的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-04-04
Android編程實(shí)現(xiàn)根據(jù)經(jīng)緯度查詢地址并對(duì)獲取的json數(shù)據(jù)進(jìn)行解析的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)根據(jù)經(jīng)緯度查詢地址并對(duì)獲取的json數(shù)據(jù)進(jìn)行解析的方法,結(jié)合實(shí)例形式分析了Android的經(jīng)緯度地址解析與json格式數(shù)據(jù)操作相關(guān)技巧,需要的朋友可以參考下2017-02-02
使用AndroidStudio上傳忽略文件至SVN Server的解決辦法
這篇文章主要介紹了使用AndroidStudio上傳忽略文件至SVN Server的解決辦法 的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06
Android使用原生組件WebView加載網(wǎng)頁和數(shù)據(jù)的方法
這篇文章主要介紹了Android使用原生組件WebView加載網(wǎng)頁和數(shù)據(jù)的方法的相關(guān)資料,需要的朋友可以參考下2016-09-09
Android Volley擴(kuò)展實(shí)現(xiàn)支持進(jìn)度條的文件上傳功能
這篇文章主要為大家詳細(xì)介紹了Android Volley擴(kuò)展實(shí)現(xiàn)文件上傳與下載功能,支持進(jìn)度條,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12

