【发布时间】:2017-09-27 22:36:50
【问题描述】:
单击按钮时关闭软键盘后,我想在LinearLayout 下显示一个PopUpWindow。
这就是我要找的
当用户单击按钮时,键盘隐藏,然后弹出窗口显示在LinearLayout(最初的键盘区域)下。喜欢下面这张图
我试试这个代码:
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);
}
}
但是以这样的方式结束PopUpWindow:
包含按钮的LinearLayout,隐藏键盘时进入屏幕底部,PopUpWindow显示在LinearLayout之上,因此它变得不可见。如下图:
那么我怎样才能得到像第一张图片一样的欲望行为呢?PopUpWindow 在键盘隐藏后显示在LinearLayout 下。
【问题讨论】: