0

I want to show a PopUpWindow under a LinearLayout after closing soft keyboard when clicking a button.

This is what I looking for

When user click the button,the keyboard hide,then the PopUpWindow show under the LinearLayout(area of the keyboard initially). Like this picture below

This is what I looking for

I try this code:

button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //hide the keyboard
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

            LinearLayout bottomBar = (LinearLayout)findViewById(R.id.bottomBar);

            LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            View popupView = inflater.inflate(R.layout.popup_window, null);

            // create the popup window
            int width = LinearLayout.LayoutParams.MATCH_PARENT;
            int height = LinearLayout.LayoutParams.WRAP_CONTENT;
            boolean focusable = true; dismiss it
            final PopupWindow popupWindow = new PopupWindow(popupView, width, height, focusable);

            // show the popup window
            popupWindow.showAtLocation(bottomBar, Gravity.BOTTOM, 0, 0);
       }
   }

But end up the PopUpWindow show like this:

The LinearLayout which contain the button,going to the bottom of screen when the keyboard is hide,the PopUpWindow show on top of the LinearLayout,so it become invisible.Like the image below:

enter image description here

So how can I get the desire behavior like the 1st picture?PopUpWindow show under the LinearLayout after the keyboard is hide.

ken
  • 2,426
  • 5
  • 43
  • 98

1 Answers1

0

Why are you trying to do this with popup window. I would suggest you to keep it simple layout. This layout will contain both the views (the layout with button and the popup layout under it). Just add this layout at the bottom of your screen and set the visibility of popup layout visibility VISIBLE/GONE whenever required. You can add the animation while showing or hiding the popup layout with help of this: Show/Hide View using Slide Up and Down Animation.

Satya
  • 149
  • 1
  • 6
  • I tried.but the whole layout is moving in order to popup the layout.but not showing the popup smoothly – ken Sep 27 '17 at 14:41