■PopupWindowを使う
// 中身のViewの生成 LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View contentView = inflater.inflate(R.layout.content, null); // popupウィンドウの生成 popupWindow = new PopupWindow(contentView); popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT); popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
以下のコードで表示できる。
View contentView = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0); popupWindow.showAtLocation(contentView, Gravity.BOTTOM, 0, 0);
廃案
DialogFragmentを使う
PopupWindowと似たような表示ができると思い試してみたがKeyBoardの上に表示することができなかった。
public static class SampleDialog extends DialogFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().getWindow().setGravity(Gravity.BOTTOM); getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); return super.onCreateView(inflater, container, savedInstanceState); } }
以下のコードで表示できる。
SampleDialog dialog = new SampleDialog(); dialog.show(getSupportFragmentManager(), "hoge");