0

I'm looking into creating a custom project selector aka spinner for my App. I want something like what you can see in the Slack app when you click on the room you're in.

I think this is a Spinner with a good old dialog mode but I'm not sure how I do the following:

1) Remove the background tint (outside of the dialog)
2) Anchor the dialog at the top rather than the centre of the screen.

This is the example:

collapsed clicked

vkislicins
  • 3,331
  • 3
  • 32
  • 62
  • a) Post photo of what you are trying to achieve b) Post some code of what you are doing – Sharjeel Jul 29 '15 at 17:32
  • added the photos - don't have any code yet but I'm not asking about the implementation of the actual spinner dropdown item or spinner item - I can figure that out. It's the positioning of the dialog that I'm not sure about and the tint behind the dialog that you get by default with `android:spinnerMode="dialog"` - that's assuming the spinner is in dialog mode. – vkislicins Jul 29 '15 at 17:45
  • Not answer but if you are using L release or support library then overflow menu will automatically show over App Bar. See menu section: http://www.google.com/design/spec/layout/structure.html - PS: There's ListPopupWindow that you should also look into http://developer.android.com/reference/android/widget/ListPopupWindow.html – Sharjeel Jul 29 '15 at 19:09
  • http://stackoverflow.com/questions/30184021/how-to-realize-this-custom-popup-menu-with-material-design-android – Sharjeel Jul 29 '15 at 19:11

1 Answers1

0

So this is what I ended up doing if anyone faces a similar problem:

spinner.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() != MotionEvent.ACTION_DOWN) {
                return true;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                  //code goes here
                }
            });

            AlertDialog dialog = builder.create();
            dialog.setCanceledOnTouchOutside(true);
            WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();

            wmlp.dimAmount=0.0f;
            wmlp.gravity = Gravity.TOP | Gravity.LEFT;
            wmlp.x = 100;   //x position
            wmlp.y = 100;   //y position

            dialog.getWindow().setAttributes(wmlp);
            dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            dialog.show();

            return true;
        }
    });

The answer is based on Show AlertDialog in any position of the screen so thanks a lot to the original author!

Community
  • 1
  • 1
vkislicins
  • 3,331
  • 3
  • 32
  • 62