【问题标题】:Android show alert dialog on bottom right, and use activity while it is shownAndroid 在右下角显示警报对话框,并在显示时使用活动
【发布时间】: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


【解决方案1】:

好的,我发现了。感谢@Bojan Kseneman

您可以使用 PopupWindow。您可以将其位置设置为您想要的任何位置。谷歌的例子,我敢肯定有很多。

我发现了这个:http://android-er.blogspot.com.tr/2012/03/example-of-using-popupwindow.html

它就像一个魅力! https://i.stack.imgur.com/H1hhm.png

好消息是,您可以编辑弹出窗口!这是一个布局!

再次感谢@Bojan Kseneman。你让我免于大量工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多