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)文章
android效果TapBarMenu繪制底部導(dǎo)航欄的使用方式示例
本篇文章主要介紹了android效果TapBarMenu繪制底部導(dǎo)航欄的使用方式,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-01-01Android 用HttpURLConnection訪問網(wǎng)絡(luò)的方法
下面小編就為大家分享一篇Android 用HttpURLConnection訪問網(wǎng)絡(luò)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-01-01android上實(shí)現(xiàn)0.5px線條的原理分析
這篇文章主要介紹了android上實(shí)現(xiàn)0.5px線條的原理分析,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01Android開發(fā)技巧之像QQ一樣輸入文字和表情圖像
QQ聊天輸入框,在輸入框中可以同時(shí)輸入文字和表情圖像。實(shí)際上,這種效果在Android SDK中只需要幾行代碼就可以實(shí)現(xiàn),本文將會(huì)介紹如何實(shí)現(xiàn)像QQ一樣輸入表情圖像2013-01-01Android?音頻波形圖實(shí)現(xiàn)效果示例
這篇文章主要為大家介紹了Android?音頻波形圖實(shí)現(xiàn)效果示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08Android通過LIstView顯示文件列表的兩種方法介紹
過ListView顯示SD卡中的文件列表一共有兩種方法,一是:通過繼承ListActivity顯示;二是:利用BaseAdapter顯示,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06android shape的使用及漸變色、分割線、邊框、半透明陰影
這篇文章主要介紹了android shape的使用及漸變色、分割線、邊框、半透明陰影,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-08-08android分享純圖片到QQ空間實(shí)現(xiàn)方式
今天小編就為大家分享一篇關(guān)于android分享純圖片到QQ空間實(shí)現(xiàn)方式,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-04-04