最近在做项目的时候,遇到,点击输入输入框文字后,回车的时候,软键盘隐藏时,页面和布局往上跳动一下,恢复正常,搞得体验非常不好,
其实这个问题,很好解决:
以下是我的解决办法:
<EditText
android:id="@+id/et_contact"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_40"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/contact"
android:background="@null"
android:gravity="center_vertical"
android:hint="请输入你的名字"
android:imeOptions="actionDone"
android:maxLength="20"
android:paddingRight="@dimen/dp_15"
android:singleLine="true"
android:textColor="@color/content_color"
android:textSize="@dimen/size_14"/>Activty中
et_phone.setOnKeyListener(this);
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (KeyEvent.KEYCODE_ENTER == keyCode && KeyEvent.ACTION_DOWN == event.getAction()) {
//处理事件
hideSoftKeyboard();
return true;
}
return false;
}
这样他会很平和的隐藏软键盘,不会造成页面跳动!!! 如果能解决你的问题,不要忘记了点赞!!!
关注本人博客地址链接:https://github.com/wolfking0608
本文介绍了一种在Android应用中实现软键盘平滑隐藏的方法,避免了键盘收起时页面出现跳动现象,提升了用户体验。
1265

被折叠的 条评论
为什么被折叠?



