AlertDialog背景活动 [英] AlertDialog background activity
问题描述
我有,因为我想让它显示正确的警告对话框。问题是,当我从任何活动触发警报,它会打开这似乎是一个空白的布局,然后打开空白布局内的警告对话框。我希望我的提醒对话框中的用户是时候触发它的活动开启。这是我的code:
I have an alert dialog that displays correctly as I intend it to. The problem is that when I trigger the alert from any activity, it opens what appears to be a blank layout then opens the alert dialog box inside the blank layout. I want my alert dialog box to open in the activity that the user is in when they trigger it. This is my code:
AlertDialog dialog = new AlertDialog.Builder(this)
.setCancelable(false)
.setView(getLayoutInflater().inflate(R.layout.activity_about_t2m, null))
.create();
dialog.setTitle("About T2M");
dialog.show();
我认为问题可能出在第二个说法,但我怎么连检测当前的活动?
I thought that the problem may be the second argument but how do I even detect the current activity?
推荐答案
试试这个: -
要建立一个AlertDialog:
To build an AlertDialog:
// 1. Instantiate an AlertDialog.Builder with its constructor
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// 2. Chain together various setter methods to set the dialog characteristics
builder.setMessage(R.string.dialog_message)
.setTitle(R.string.dialog_title);
// 3. Get the AlertDialog from create()
AlertDialog dialog = builder.create();
您也可以参考 http://developer.android.com /guide/topics/ui/dialogs.html#DialogFragment 进一步的参考。
You can also refer the http://developer.android.com/guide/topics/ui/dialogs.html#DialogFragment for further reference.
这篇关于AlertDialog背景活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!