// 获取编辑框焦点 editText.setFocusable(true);
activity_friend_ring_bottom.setFocusable(true); activity_friend_ring_bottom.setFocusableInTouchMode(true); activity_friend_ring_bottom.requestFocus(); //打开软键盘 InputMethodManager imm = (InputMethodManager) ctx .getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); //关闭软键盘 imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
/** 定义PopupWindow **/ private void initPopuWindow() { View view = getLayoutInflater().inflate(R.layout.adapter_friend_ring_replay_dialog, null); selectPopupWindow = new PopupWindow(view, android.view.ViewGroup.LayoutParams.FILL_PARENT,android.view.ViewGroup.LayoutParams.WRAP_CONTENT, false); selectPopupWindow.setFocusable(true); selectPopupWindow.setBackgroundDrawable(new BitmapDrawable()); selectPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); selectPopupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0); InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); im.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); }
// 注意必须在AndroidManifest.xmlAndroidManifest.xml文件中添加android:windowSoftInputMode="adjustPan" 防止键盘关闭的时候是黑色
本文介绍如何在Android应用中控制软键盘的显示与隐藏,并展示了PopupWindow的创建及设置方法。通过代码示例,详细解释了如何使EditText获得焦点以自动弹出软键盘,同时提供了关闭软键盘的方法。此外,还介绍了如何初始化并展示PopupWindow。
1万+

被折叠的 条评论
为什么被折叠?



