android Popupwindow被弹出软键盘挡住
来源:互联网 发布:淘宝店铺模板市场 编辑:程序博客网 时间:2024/06/07 06:14
之前做过一个页面包含有PopupWindow,PopupWindow中有EditText输入框,点击EditText输入内容PopupWindow从屏幕底部弹出,软键盘直接把PopupWindow给挡住了。
当输入内容的时候我们希望软键盘不会把PopupWindow给挡住,不影响用户的正常输入,该怎么办呢,现在说一下方法,在设置PopupWindow的时候加上如下两行代码
popupWindow.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
这两行代码的先后顺序不能变,否则不能解决问题,是不是很另类,修改后的结果如下图,是不是发现软键盘把PopupWindow整个往上推上去了,完全不影响用户的正常输入
以上示例图片为本人实测的截图,现贴出所有代码,想看具体效果的 同学可以自己测试一下
[java] view plain copyimport android.app.Activity; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.view.WindowManager; import android.widget.Button; import android.widget.PopupWindow; import com.example.mydemo.R; public class TestPopWindow extends Activity { private PopupWindow popview; private Button btn_open; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); this.setContentView(R.layout.test_popwindow); btn_open = (Button) this.findViewById(R.id.btn_open); btn_open.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { showPopWindow(); } }); } private void showPopWindow() { View view = LayoutInflater.from(this).inflate(R.layout.view_pop, null); popview = new PopupWindow(view, android.view.ViewGroup.LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, true); popview.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); popview.setFocusable(true); // 设置点击其他地方就消失 popview.setOutsideTouchable(true); popview.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED); popview.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); popview.showAtLocation(findViewById(R.id.btn_open), Gravity.BOTTOM | Gravity.CENTER_VERTICAL, 0, 0); } } test_popwindow.xml布局文件[java] view plain copy<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:orientation="vertical" > <Button android:id="@+id/btn_open" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:text="open" /> </RelativeLayout> view_pop.xml布局文件[java] view plain copy<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <EditText android:id="@+id/et_input" android:layout_width="fill_parent" android:layout_height="40dip" android:singleLine="true" android:textSize="16sp" > </EditText> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/et_input" android:layout_marginTop="20dip" android:gravity="center_horizontal" android:orientation="horizontal" > <Button android:id="@+id/confirm" android:layout_width="80dip" android:layout_height="wrap_content" android:layout_marginRight="30dip" android:text="确定" /> <Button android:id="@+id/cancel" android:layout_width="80dip" android:layout_height="wrap_content" android:layout_marginLeft="30dip" android:text="取消" /> </LinearLayout> </RelativeLayout>
阅读全文
0 0
- android Popupwindow被弹出软键盘挡住
- android Popupwindow被弹出软键盘挡住
- android popupwindow 中输入框被软键盘弹出挡住问题解决
- android 使用PopupWindow弹窗时,挡住了软键盘
- android软键盘挡住界面
- Android 弹出软键盘遮住Popupwindow的解决
- edittext 被软键盘挡住
- EditText被软键盘挡住
- 软键盘弹出+popupWindow的问题
- Android WebView 软键盘挡住输入框
- 解决Popupwindow挡住软键盘问题
- android弹出软键盘
- Android软键盘弹出
- Android软键盘弹出
- EditText被软键盘挡住一部分
- 软键盘挡住EditText
- Android总结笔记04:仿QQ空间登录UI,解决软键盘弹出挡住输入框的问题
- Android安卓WebApp中 全屏和普通模式下 webview中软键盘弹出挡住输入框 解决方案
- 记录no static method cannot be reference
- Stanford机器学习---第一讲. Linear Regression with one variable
- 学习日志2017.12.18
- JPA随手笔记
- 1008. 数组元素循环右移问题 (20)
- android Popupwindow被弹出软键盘挡住
- CSS-怪异盒模型和标准盒模型
- 20个非常有用的Java程序片段
- cookie、 sessionStorage 、localStorage之间的区别和使用
- 无法安装64位版本的微软Office
- Spring IOC
- [Vim]注释代码的四种姿势
- python出现中文错误:SyntaxError: Non-ASCII character '\xe7' in file car-training.py on line 7, but no encod
- 行内元素padding-left用百分比