Android:如何创建自定义下拉对话框?

时间:2019-07-04 10:47:29

标签: android dialog

我需要创建一个对话框,该对话框从屏幕上的单击位置下拉。

我已经考虑过使用浮动ContextMenu,但是我需要自定义下拉菜单的内容以显示自己的views

context menu

我还考虑过使用自定义DialogFragment,但这还不够细微,会中断流程。

enter image description here

如何在两者之间创建内容?

一个完美的例子是Duolingo使用的下拉对话框:

good example

我还考虑过将framelayout添加到用户点击的位置,但是我不确定如何在对话框出现时重新创建ContextMenu的部门或如何创建体面的动画。正在淡入淡出。

我不想在对话框中显示选项列表,我想显示包含textviewsbuttons数量的自定义布局。

1 个答案:

答案 0 :(得分:2)

检查这些库,它将为您提供帮助

https://github.com/MasayukiSuda/BubbleLayout?utm_source=android-arsenal.com&utm_medium=referral&utm_campaign=3564

https://github.com/piruin/quickaction?utm_source=android-arsenal.com&utm_medium=referral&utm_campaign=5746

您还可以在不使用库的情况下创建它:

  1. 创建自定义对话框
  2. 设置对话框动画

    override Dialog onCreateDialog(Bundle savedInstanceState){
        ...
        Dialog dialog = new Dialog(context);
        dialog.setWindowAnimations(R.style.anim_dropdown);
        return dialog;
    }
    
  3. Changing position of the Dialog on screen android