導航:首頁 > 操作系統 > android對話框圖片

android對話框圖片

發布時間:2022-08-18 17:53:28

『壹』 android中的對話框怎麼寫

Activities提供了一種方便管理的創建、保存、回復的對話框機制,例如onCreateDialog(int),onPrepareDialog(int,Dialog),showDialog(int),dismissDialog(int)等方法,如果使用這些方法的話,Activity將通過getOwnerActivity()方法返回該Activity管理的對話框(dialog).

onCreateDialog(int):當你使用這個回調函數時,Android系統會有效的設置這個Activity為每個對話框的所有者,從而自動管理每個對話框的狀態並掛靠到Activity上。這樣,每個對話框繼承這個Activity的特定屬性。比如,當一個對話框打開時,菜單鍵顯示為這個Activity定義的選項菜單,音量鍵修改Activity使用的音頻流。

showDialog(int):當你想要顯示一個對話框時,調用showDialog(intid)方法並傳遞一個唯一標識這個對話框的整數。當對話框第一次被請求時,Android從你的Activity中調用onCreateDialog(intid),你應該在這里初始化這個對話框Dialog。這個回調方法被傳以和showDialog(intid)相同的ID。當你創建這個對話框後,在Activity的最後返回這個對象。

onPrepareDialog(int,Dialog):在對話框被顯示之前,Android還調用了可選的回調函數onPrepareDialog(intid,Dialog).如果你想在每一次對話框被打開時改變它的任何屬性,你可以定義這個方法。這個方法在每次打開對話框時被調用,而onCreateDialog(int)僅在對話框第一次打開時被調用。如果你不定義onPrepareDialog(),那麼這個對話框將保持和上次打開時一樣。這個方法也被傳遞以對話框的ID,和在onCreateDialog()中創建的對話框對象。

dismissDialog(int):當你准備關閉對話框時,你可以通過對這個對話框調用dismiss()來消除它。如果需要,你還可以從這個Activity中調用dismissDialog(intid)方法,這實際上將為你對這個對話框調用dismiss()方法。如果你想使用onCreateDialog(intid)方法來管理你對話框的狀態(就如同在前面的章節討論的那樣),然後每次你的對話框消除的時候,這個對話框對象的狀態將由該Activity保留。如果你決定不再需要這個對象或者清除該狀態是重要的,那麼你應該調用removeDialog(intid)。這將刪除任何內部對象引用而且如果這個對話框正在顯示,它將被消除。

下面是幾種對話框的效果

圖一:

圖1效果:該效果是當按返回按鈕時彈出一個提示,來確保無誤操作,採用常見的對話框樣式。


代碼:
創建對話框方法dialog()

protected void dialog() {
AlertDialog.Builder builder = new Builder(Main.this);
builder.setMessage("確認退出嗎?"); builder.setTitle("提示"); builder.setPositiveButton("確認", new OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); Main.this.finish();
}
}); builder.setNegativeButton("取消", new OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}); builder.create().show();
}

在onKeyDown(int keyCode, KeyEvent event)方法中調用此方法

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
dialog();
}
return false;
}

圖2效果:改變了對話框的圖表,添加了三個按鈕

Dialog dialog = new AlertDialog.Builder(this).setIcon(
android.R.drawable.btn_star).setTitle("喜好調查").setMessage(
"你喜歡李連傑的電影嗎?").setPositiveButton("很喜歡",
new OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(Main.this, "我很喜歡他的電影。",
Toast.LENGTH_LONG).show();
}
}).setNegativeButton("不喜歡", new OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(Main.this, "我不喜歡他的電影。", Toast.LENGTH_LONG)
.show();
}
}).setNeutralButton("一般", new OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(Main.this, "談不上喜歡不喜歡。", Toast.LENGTH_LONG)
.show();
}
}).create(); dialog.show();

圖3效果:信息內容是一個簡單的View類型

new AlertDialog.Builder(this).setTitle("請輸入").setIcon(
android.R.drawable.ic_dialog_info).setView(
new EditText(this)).setPositiveButton("確定", null)
.setNegativeButton("取消", null).show();

圖4效果:信息內容是一組單選框

new AlertDialog.Builder(this).setTitle("復選框").setMultiChoiceItems(
new String[] { "Item1", "Item2" }, null, null)
.setPositiveButton("確定", null)
.setNegativeButton("取消", null).show();

圖5效果:信息內容是一組多選框

new AlertDialog.Builder(this).setTitle("單選框").setIcon(
android.R.drawable.ic_dialog_info).setSingleChoiceItems(
new String[] { "Item1", "Item2" }, 0,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setNegativeButton("取消", null).show();

圖6效果:信息內容是一組簡單列表項

new AlertDialog.Builder(this).setTitle("列表框").setItems(
new String[] { "Item1", "Item2" }, null).setNegativeButton(
"確定", null).show();

圖7效果:信息內容是一個自定義的布局

1.布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:background="#ffffffff" android:orientation="horizontal"
android:id="@+id/dialog">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/tvname" android:text="姓名:" />
<EditText android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/etname" android:minWidth="100dip"/></LinearLayout>

2.調用代碼

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.dialog,
(ViewGroup) findViewById(R.id.dialog)); new AlertDialog.Builder(this).setTitle("自定義布局").setView(layout)
.setPositiveButton("確定", null)
.setNegativeButton("取消", null).show();

『貳』 android如何創建帶3個按鈕的對話框

1.先在布局界面上,拖進來一個按鈕控制項,並設置顯示的文字,記得保存(Ctrl+S)

之後在代碼界面上定義該按鈕。

2.新建一個按鈕點擊的方法。
onClick(View v) :點擊之後的動作。

3.設置按鈕的點擊事件指向我們新建的點擊方法。
setOnClickListener:設置點擊之後觸發的動作。

4.在onClick里添加彈出對話框的代碼。
AlertDialog:一個對話框類。
MainActivity.this:對話框顯示的位置。
setTitle:設置標題。
setMessage:設置內容。
setPositiveButton:設置對話框的按鈕。
show():顯示對話框。

至此所有代碼已經完成,編譯並生成,在Android安卓虛擬機上顯示如下。

『叄』 安裝 Android SDK Manager出錯,彈出來的對話框如下圖,我是W7家庭版,請問怎麼辦啊

這個不是出錯了android sdk Manager log指的是android sdk管理器日誌,點擊close就行了

『肆』 android里listView的item點擊後,彈出一個上面是圖片,下面是文字的的對話框,怎麼做

1.設置item監聽事件
2.自定義對話框(Layout上面是ImageView下面是TextView)

『伍』 android怎麼實現自定義對話框的背景

我知道你出現什麼問題了,你是不是寫了一個類繼承了Dialog,然後再實例化,這個dialog,但是button按鈕美發添加監聽器是不? 如果你要是自己繼承了DIalog的話,那麼我們看看源碼把! Dialog implements DialogInterface 也就是說Dialog繼承了 DialogInterface這個介面 好的 我們再看看DialogInterface這個介面把 我們會發現DialogInterface 有一個方法: public static interface OnClickListener { public abstract void onClick(DialogInterface dialoginterface, int i); } 好的 那麼也就是如果我們繼承了Dialog的話,我們同樣也繼承了DialogInterface這個介面的ONclickListner方法所以我們再給button設置onclicklistner的時候就會出錯,因為本身就是不同包的東西,現在放到一個類裡面肯定就會出錯! 解決方法:在給button 設置點擊事件的時候,加上完整的包名就行了! 專門給你敲了個例子你看看: Activity裡面: public class QuestionActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { Dialog ad = new MyDialog(this); ad.show(); return super.onKeyDown(keyCode, event); } } 自定義Dialog裡面: public class MyDialog extends Dialog { Context context; public MyDialog(Context context) { super(context); this.context = context; init(); } public void init() { LinearLayout ll = new LinearLayout(context); ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); Button btn = new Button(context); btn.setText("hello"); /************************************************************/ btn.setOnClickListener(new android.view.View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(context, "hello", 0).show(); MyDialog.this.dismiss(); } }); /**********************************************************/ ll.addView(btn); this.setContentView(ll); } } 注意*****行裡面

『陸』 JAVA的android的載入自定義對話框問題!!具體請請看圖片!

AlertDialog.Builder builder
這個變數要升級為全局變數,去掉final修飾符。因為你這個變數是在onCreate函數里聲明的,出了這個函數後就被棧回收了,內存就沒有這個變數了,但是你點擊按鈕的時候,肯定是出了onCreate函數了。而升級為全局變數後,你在onCreate函數初始化後,它一直都在,直到你退出當前Activity。
也可以在onClick(View source)函數裡面聲明這個變數,聲明方式要注意new AlertDialog.Builder構造函數所帶參數不是this了,是AlertDialog.Builder(當前類名.this)。

『柒』 android 如何在 dialog 中添加圖片

一般來說
在Android里顯示Gif圖片,只會顯示第一幀。如果想顯示gif圖片的話可以用Movie來顯示圖片

在dialog顯示圖片可以使用AlertDialog
載入一個布局,布局中顯示你所要顯示的圖片。比如
LayoutInflater
inflater
=
getLayoutInflater();
View
layout
=
inflater.inflate(R.layout.dialog,
(ViewGroup)
findViewById(R.id.dialog));
new
AlertDialog.Builder(this).setTitle("自定義布局").setView(layout)
.setPositiveButton("確定",
null)
.setNegativeButton("取消",
null).show();
希望能幫到你。

『捌』 Android UI開發中,設置Activity的什麼屬性可以使Activity顯示為對話框樣式.

將activity設置成對話框樣式,只需在activity屬性裡面增加下面一句代碼:

『玖』 android開發,我想把多選對話框的文字都換成我自己做的圖片,代碼應該怎麼寫不是在主Activity中的。

構建新的對象,繼承對話框對象。裡面有設置圖片的方法,想要什麼自己設置,不光是圖片,能換的東西多了。用自己構建的對象就可以了。

閱讀全文

與android對話框圖片相關的資料

熱點內容
linux強制退出命令 瀏覽:321
韓國高分電影愛情推理片 瀏覽:445
同截面梁箍筋加密 瀏覽:220
肉一點的有聲小說 瀏覽:457
程序員情感語錄 瀏覽:901
喀什雲存儲伺服器 瀏覽:89
看片網址貼吧 瀏覽:200
酷安下載不了app如何解決 瀏覽:357
各種排序演算法思想 瀏覽:339
雲伺服器便簽怎麼拿出來 瀏覽:797
有部外國電影一群人在游泳 瀏覽:285
在哪能看島國片 瀏覽:175
客戶端如何讀取伺服器 瀏覽:365
附近電影院訂票 瀏覽:614
好孩子狼孩電影播放 瀏覽:880
中國男人和外國女孩電影 瀏覽:325
趙薇拍的電影 瀏覽:920
python如何合並多個excel文件 瀏覽:865
南宮嬌離微揚免費閱讀 瀏覽:43
2023台灣同性電影 瀏覽:846