只要焦点位于edittext上。键盘已打开,所有视图均已调整并向上移动,如下面的示例图像所示。
Button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FileUtils.hideKeyboard(MainActivity.this);
LayoutInflater layoutInflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customView = layoutInflater.inflate(R.layout.layout,null);
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
popupWindow = new PopupWindow(customView, width, 300);
//display the popup window
popupWindow.showAtLocation(rootlayout, Gravity.BOTTOM, 0, 0);
}
});
此代码工作正常,但弹出窗口显示在屏幕底部,并且停留在rootlayout上。我希望此弹出窗口处于打开状态,并像带有动画的键盘一样保持打开状态。
您可以为此使用底部对话框
BottomSheetDialog dialog = new BottomSheetDialog(YourActivity.this);
dialog.setContentView(YourView);
dialog.show();