Android EditText弹出软键盘实现页面标题头不动,软键盘弹出在编辑框下面
来源:互联网 发布:python和c语言 编辑:程序博客网 时间:2024/05/29 06:47
为了实现EditText编辑的时候弹出软键盘标题头不动,底部编辑框上移,想了好多种方法,也百度,问同事每种办法都有问题,在这总结一下,希望能帮助到大家。
上图看下效果:
可以看到弹出键盘的时候,只有EditText在软键盘上面,还有一个蓝色点,这个随后再说。
用RelativeLayout实现的父布局id为root,试验过很多种方法,总结一下,想要实现这种效果,有一个原则 EditText所在的布局中,必须位于root的底部,也就是写android:layout_alignParentBottom=”true”这个属性,然后再根据具体情况调整布局。
为了更简单的实现功能,页面算是最简单的实现了,现在说一下那个蓝色的点,他是位于EditText上面也就是用了above属性,所以我们可以看到它也被弹到布局上面。
总结一下规律就是,RelativeLayout在弹出软键盘的时候先寻找android:layout_alignParentBottom属性是否有控件设置为true,如果有将此控件向上移动键盘高度的位置,布局也就位于软键盘的上面,其他控件如果有相对于该控件的位置,也就相对的移动了,如果没有则什么都不做,可以看做布局是一层一层盖上去的,键盘弹出的时候,只把符合要求的当层的布局向上移动,所以如果我们按照这种方法写,肯定是可以的。
还有一个重点就是,配置文件里面该activity要设置android:windowSoftInputMode=”adjustResize”
相信还有小伙伴会遇到设置之后不生效的结果,那就在布局文件的根布局添加android:fitsSystemWindows=”true”属性,但是有的还会有问题,如果代码中有设置状态栏颜色的,会多出一条状态栏高度的空白条,这个还不知道如何解决。
也是经过很多实验发现的,表述不是很清楚,不懂得可以沟通,希望可以帮助到大家吧,毕竟感觉这个坑不大不小,但却挺烦人的。有大神也可以给出更权威的答案,相互学习,共同进步。
在此附上代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rl_root_view" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:background="@color/white"> <include android:id="@+id/ll_title_bar" layout="@layout/appbar"/> <LinearLayout android:id="@+id/ll_center" android:layout_width="match_parent" android:layout_below="@+id/ll_title_bar" android:orientation="vertical" android:layout_height="wrap_content"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="test 111" android:layout_margin="10dp" android:padding="10dp" android:background="@color/error_stroke_color" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="test 222" android:layout_margin="10dp" android:padding="10dp" android:background="@color/error_stroke_color" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="test 333" android:layout_margin="10dp" android:padding="10dp" android:background="@color/error_stroke_color" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="test 4444" android:layout_margin="10dp" android:padding="10dp" android:background="@color/error_stroke_color" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="test 555" android:layout_margin="10dp" android:padding="10dp" android:background="@color/error_stroke_color" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="test 6666" android:layout_margin="10dp" android:padding="10dp" android:background="@color/error_stroke_color" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="test 777" android:layout_margin="10dp" android:padding="10dp" android:background="@color/error_stroke_color" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="test 888" android:layout_margin="10dp" android:padding="10dp" android:background="@color/error_stroke_color" /> </LinearLayout> <EditText android:id="@+id/et_test" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:hint="EditText" android:background="@color/blue_btn_bg_color" android:padding="10dp" /> <ImageView android:layout_width="10dp" android:layout_height="10dp" android:layout_above="@+id/et_test" android:layout_centerHorizontal="true" android:background="@color/colorPrimary"/></RelativeLayout>
- Android EditText弹出软键盘实现页面标题头不动,软键盘弹出在编辑框下面
- Android EditText弹出软键盘实现页面标题头不动,软键盘弹出在编辑框下面
- 点击edittext系统弹出软键盘,保证标题不动,输入框在输入法上面
- android实现软键盘弹出,editText随键盘上移,背景不动
- android实现软键盘弹出,editText随键盘上移,背景不动
- Android避免进入页面EditText自动弹出软键盘
- Android避免进入页面EditText自动弹出软键盘
- android edittext不弹出软键盘
- android edittext不弹出软键盘
- android防止EditText自动弹出软键盘
- android防止EditText自动弹出软键盘
- android edittext不弹出软键盘
- android edittext不弹出软键盘
- android EditText软键盘弹出控制
- Android EditText 禁止软键盘弹出
- android edittext不弹出软键盘
- edittext禁止android软键盘弹出
- android EditText不自动弹出软键盘
- Spring中应用占位符需引入的配置
- SPARK各种提交方式总结
- Echart 如何显示百分比
- PL SQL的事务管理
- 【智库2861】大数据和小数据
- Android EditText弹出软键盘实现页面标题头不动,软键盘弹出在编辑框下面
- java swing中使用jsch做sftp文件上传
- Java开发Excel POI getPhysicalNumberOfCells 与 getLastCellNum的区别
- 数据库
- spring Cloud笔记
- Mac 隐藏文件查看及关闭
- 除法取模与逆元
- Go语言学习笔记(五)-其他类型(指针、结构体、、)
- ArrayList的add和remove方法