【发布时间】:2017-08-21 19:09:12
【问题描述】:
我正在尝试显示一个对话框。但我希望它位于视图的右下角,并且我想在对话框停留在那里时使用该活动。怎么解决?
这就是我得到的
这就是我想要的
如果需要,这是我的 DialogFragment 类:
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
public class FireMissilesDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("Test")
.setPositiveButton("Fire", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
感谢您的帮助:)
【问题讨论】:
-
我认为您不应该使用对话框,使用文本和按钮创建视图并将其放置在右下角。对话框会暂停您的活动,直到采取行动。
-
@BojanKseneman 很好的解决方案,但我的项目中有不止一个活动,为每个活动添加文本和按钮真的很难。
-
你喜欢然后使用 PopupWindow [developer.android.com/reference/android/widget/….您可以将其位置设置为您想要的任何位置。谷歌的例子,我敢肯定有很多。
-
@BojanKseneman 这正是我想要的!感谢您的帮助:)
标签: java android android-activity dialog