布局:
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="@color/color_f4f4f5">
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"/>
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"/>
初始化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);//延遲彈出
}
本文地址:https://blog.csdn.net/wang670144941/article/details/107932586
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态