定时模式对话框 [英] timed modeless dialog
问题描述
有没有办法显示一个无模式对话框 - 一个对话框,允许用户与任何是对话框之前在屏幕上互动,也可以让用户使用,如果pressed的对话互动。
Is there any way to show a modeless dialog--a dialog that allows the user to interact with whatever was on the screen before the dialog but also allows the user to interact with the dialog if pressed?
我知道敬酒的,但他们不允许用在弹出的互动。
I know of Toasts, but they don't allow interaction with the popup.
我知道对话框的,但他们是模态的,不允许与后台交互。
I know of Dialogs, but they're modal and don't allow interaction with the background.
我知道的通知,但我想要的东西是visibile在屏幕上。
I know of Notifications, but I want something that is visibile on screen.
基本上,我希望能够为玩游戏或东西,一个弹出窗口,我有一个新的电子邮件或东西。我可以点击它来查看我的电子邮件,但我可以等待它走,如果我只是想继续玩我的游戏。这是可能在Android中?
I basically want to be able to be playing a game or something and a popup appears that I have a new email or something. I can click it to view my email, but I can wait for it to go away if I just want to continue playing my game. Is this possible in Android?
推荐答案
是,创建有型有款的活动 Theme.Dialog
。这是一个正常的活动,看起来像一个对话框,而被无模式和接受事件
Yes, create an Activity with style Theme.Dialog
. This is a normal activity which looks like a dialog, while being modeless and accepting events.
一个例子:
<activity android:name=".activity.dialog.PhotoDialog"
android:label="@string/photo_dialog_title"
android:theme="@android:style/Theme.Dialog"/>
编辑
确实 Theme.Dialog
模糊的基本活动,并使其不可访问。我有一个类似的规定在这里我必须说明的文字上传进度对话框和取消按钮。主要的缺点是在制定 WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
和重置 WindowManager.LayoutParams.FLAG_DIM_BEHIND
。
Indeed Theme.Dialog
blurs the underlying activity and makes it unaccessible. I had a similar requirement here I had to show upload progress dialog with text and cancel button. The main catch is in setting WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
and resetting WindowManager.LayoutParams.FLAG_DIM_BEHIND
.
创建一个对话框,使用自定义内容:
Created a Dialog with custom content:
if (progressDialog == null) {
progressDialog = new Dialog(activityRequestingProgressDialog);
progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
progressDialog.setContentView(R.layout.progress_upload);
progressBar = (ProgressBar) progressDialog.findViewById(R.id.progressBar);
progressText = (TextView) progressDialog.findViewById(R.id.progressText);
progressText.setText("0 %");
progressText.setTextSize(18);
Button buttonCancel = (Button) progressDialog.findViewById(R.id.btnCancel);
buttonCancel.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
cancelProgressDialog();
stopUpload("Upload cancelled.");
}
});
Window window = progressDialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setGravity(Gravity.BOTTOM);
progressDialog.show();
}
progressText.setText(text);
progressBar.setProgress(percent);
这是此对话框的布局:
And this is the layout for this Dialog:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/progressDialog"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="18sp"
android:padding="10dp"
android:text="@string/progress_title"/>
<LinearLayout android:id="@+id/progressDialog"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="10dp"
android:layout_centerVertical="true">
<ProgressBar android:id="@+id/progressBar"
android:layout_width="150dp"
android:layout_height="34dp"
android:paddingRight="10dp"
android:max="100"
android:progress="0"
android:fadingEdge="vertical"
style="?android:attr/progressBarStyleHorizontal"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/progressText"
android:paddingRight="10dp"/>
<Button android:layout_height="40dp"
android:layout_width="80dp"
android:id="@+id/btnCancel"
android:text="@string/dialog_cancel"/>
</LinearLayout>
</LinearLayout>
这篇关于定时模式对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!