問題描述
我想在 Activity 上顯示一個對話框,但仍想在顯示對話框時與后臺 Activity 交互以執(zhí)行某些操作.如何做到這一點?
I want to display a dialog over an activity but still want to interact with background activity to perform something, while the dialog is being displayed. How can this be done?
推薦答案
使用 DialogFragment,它是一個顯示對話窗口的片段,浮動在其活動窗口的頂部.該片段包含一個 Dialog 對象,它會根據(jù)片段的狀態(tài)適當?shù)仫@示該對象.對話框的控制(決定何時顯示、隱藏、關閉它)應該通過這里的 API 來完成,而不是直接調用對話框,所以你的 Activity 仍然處于控制之中.
Use a DialogFragment, which is a fragment that displays a dialog window, floating on top of its activity's window. This fragment contains a Dialog object, which it displays as appropriate based on the fragment's state. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog, so your Activity remains in control.
這篇關于在android中顯示對話框時我們可以與后臺活動交互嗎的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!