当前位置: 代码迷 >> 综合 >> Android popupwidown?实现朋友圈评论弹窗显示在软键盘上面
  详细解决方案

Android popupwidown?实现朋友圈评论弹窗显示在软键盘上面

热度:41   发布时间:2024-02-09 13:25:54.0

布局:

<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:focusable="true"android:focusableInTouchMode="true"android:background="@color/color_f4f4f5"><EditTextandroid:id="@+id/popup_circle_comment_edit"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="?text_size_normal"android:layout_marginTop="8dp"android:clickable="true"android:enabled="true"android:layout_marginBottom="8dp"android:layout_marginStart="10dp"android:textColor="@color/color_303133"android:padding="6dp"android:layout_toStartOf="@+id/popup_circle_comment_send"android:background="@drawable/shape_radius5_white"/><TextViewandroid:id="@+id/popup_circle_comment_send"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="@color/color_606266"android:textSize="?text_size_normal"android:text="发送"android:paddingTop="6dp"android:paddingBottom="6dp"android:paddingStart="10dp"android:paddingEnd="10dp"android:layout_alignParentEnd="true"android:layout_marginEnd="8dp"android:layout_marginStart="8dp"android:layout_centerVertical="true"android:background="@drawable/edit_layout_bg"/>
</RelativeLayout>

初始化popupwidown 

PopupWindow commentPopup = new PopupWindow(popupBinding.getRoot(), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
commentPopup.setTouchable(true);
commentPopup.setFocusable(true);
commentPopup.setOutsideTouchable(true);//点击弹窗外弹窗消失
commentPopup.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);//显示在软键盘上面配置
commentPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//显示在软键盘上面配置
commentPopup.showAtLocation(popupBinding.getRoot(), Gravity.BOTTOM, 0, 0);
showSoft();
/*** 弹出输入法窗口*/
private void showSoft() {Handler handle = new Handler();handle.postDelayed(new Runnable() {@Overridepublic void run() {//设置可获得焦点popupCircleCommentEdit.setFocusable(true); //popupCircleCommentEditpopupCircleCommentEdit.setFocusableInTouchMode(true);//请求获得焦点popupCircleCommentEdit.requestFocus();InputMethodManager inputMethodManager = (InputMethodManager)    popupCircleCommentEdit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);inputMethodManager.showSoftInput(popupCircleCommentEdit, 0);//弹出时强制让输入框popupCircleCommentEdit获取焦点}}, 200);//延迟弹出
}
  相关解决方案