关于弹出窗口的输入法挡住按钮问题

来源:互联网 发布:淘宝全国联保服务申请 编辑:程序博客网 时间:2024/05/15 06:46

网上一般提供的两种方法都是调整edittext控件的高度

方案一、把整个布局文件用ScrollView套住。这样当你聚焦时虽然输入法也能够挡住一些输入框,但是你可以通过手动滑动看被挡住的内容。

方案二、在Activity中设置android:windowSoftInputMode="adjustResize" 解释: 使得该Activity主窗口总是被调整屏幕的大小以便留出软键盘的空间。就是把布局内容顶上去一遍能够看到界面的所有内容,而不会被键盘遮挡


我们实际的需求是输完内容,可以直接点按钮提交。就是说edittext下有个按钮,我们需要看到。。。

先看下如下两张图,第一张,是弹出来的popupwindow ,黄色的edittext和下边的2个按钮。。

第二张是输入法弹出来后的效果。我们的需求就是如此:



如何实现了?方法如下,点击一个按钮调用下边的方法弹出popupwindow。。

private void popup() {
if (pWindow == null) {
View view = LayoutInflater.from(this).inflate(R.layout.mypopup,
null);
pWindow = new PopupWindow(view, ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
pWindow.setFocusable(true);
pWindow.setBackgroundDrawable(new BitmapDrawable());
pWindow.setTouchable(true);
pWindow.setOutsideTouchable(false);
pWindow.setSoftInputMode(android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
editText = (EditText) view.findViewById(R.id.etmsg);
view.findViewById(R.id.btnsend).setOnClickListener(this);
view.findViewById(R.id.btncancel).setOnClickListener(this);
}
pWindow.showAtLocation(getCurrentFocus(), Gravity.CENTER, 0, 0);
}

其中 ,mypopup.xml文件如下。原理很简单,就是让2个按钮的布局覆盖在edittext上边。。

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/FrameLayout1"    android:layout_width="match_parent"    android:layout_height="wrap_content" >    <EditText        android:id="@+id/etmsg"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:gravity="top"        android:lines="15"        android:background="#ffff00"        android:paddingBottom="50dp"         >    </EditText>    <LinearLayout        android:layout_gravity="bottom"        android:layout_height="50dp"        android:background="#00ff00"        android:layout_width="match_parent"        >        <Button            android:id="@+id/btnsend"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="send" />        <Button            android:id="@+id/btncancel"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="cancel" />    </LinearLayout></FrameLayout>


0 0
原创粉丝点击