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

布局:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:background="@color/color_f4f4f5">
    <EditText
        android: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"/>
    <TextView
        android: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() {

        @Override
        public void run() {
            //设置可获得焦点
            popupCircleCommentEdit.setFocusable(true); //popupCircleCommentEdit
            popupCircleCommentEdit.setFocusableInTouchMode(true);
            //请求获得焦点
            popupCircleCommentEdit.requestFocus();
            InputMethodManager inputMethodManager = (InputMethodManager)    
            popupCircleCommentEdit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.showSoftInput(popupCircleCommentEdit, 0);//弹出时强制让输入框popupCircleCommentEdit获取焦点
        }
    }, 200);//延迟弹出
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值