Android: Quickaction like dialog window to display other components

dOps picture dOps · Jul 15, 2013 · Viewed 8.4k times · Source

I am looking to implement a dialogbox that opens when I click a button. It should look like the popular quickaction dialog that appears in android phone and twitter app. But I should be able to use it as a container so that I can add other elements such buttons, dropdowns, text boxes etc.

Of course, it needs to pop-out of the button with an arrow pointing to the button that invoked this dialog. Any other similar example or just a barebones description of what I am supposed to implement and use should help as well.

Answer

MSA picture MSA · Jul 15, 2013

There are few examples that you can use, here are some of them:

http://shardulprabhu.blogspot.ro/2012/08/blog-post_29.html

https://github.com/lorensiuswlt/NewQuickAction

https://github.com/lorensiuswlt/NewQuickAction3D

In my opinion the first link example it's easy to understand and modify. On the other hand if you can create a custom PopupWindow and add arrow, here you have a simple popup example.

  public class MyPopup extends PopupWindow{

  public MyPopup (Context context) {
    super(context);
    this.context = context;

public void show() {

    if (context == null)
        return;

    LayoutInflater layoutInflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    layout = layoutInflater.inflate(R.layout.mypopup_layout, null);

    Display display = ((Activity) context).getWindowManager()
            .getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;


    setContentView(layout);
    setWidth(width / 4);
    setHeight(height / 2);
    setFocusable(true);

    /**
     * Clear the default translucent background
     */
    setBackgroundDrawable(new BitmapDrawable(context.getResources()));

    init();

    /**
     * Displaying the pop-up at the specified location, + offsets.
     */
    showAtLocation(layout, Gravity.NO_GRAVITY, xpos, ypos);

}


}
}

Hope you will find this usefull. Cheers