Android 关于软键盘
一、.弹出的时候显示Editext框
添加布局replay_input
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/reply_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#80808080" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<EditText
android:id="@+id/reply"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingRight="30dp" />
</RelativeLayout>
<Button
android:id="@+id/send_msg"
android:layout_width="50dip"
android:layout_height="35dp"
android:layout_margin="5dp"
android:background="@drawable/master_icon"
android:text="发送"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
2.编写代码
private PopupWindow editWindow;
View editView = mInflater.inflate(R.layout.replay_input, null);
editWindow = new PopupWindow(editView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
editWindow.setOutsideTouchable(true);
editWindow.setFocusable(true);
editWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
EditText replyEdit = (EditText) editView.findViewById(R.id.reply);
replyEdit.setFocusable(true);
replyEdit.requestFocus();
// 以下两句不能颠倒
editWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
editWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
editWindow.showAtLocation(rlPart, Gravity.BOTTOM, 0, 0);
// 显示键盘
final InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
editWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
if (imm.isActive())
imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
}
});