Android EditText输入框被键盘遮挡问题解决
16lz
2021-01-23
Android EditText输入框被键盘遮挡问题解决:
纯属做笔记:
方法:一
1.在onCreate中加上:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
2.布局:
<?xml version="1.0" encoding="utf-8"?>
这里我在ScrollView中添加了:
android:fillViewport="true"
3.清单文件中设置:
方法:二
1.全屏模式下,即使将activity的windowSoftInputMode的属性设置为:adjustResize,在键盘显示时它未将Activity的Screen向上推动
使用方法 :
在你的Activity的oncreate()方法里调用AndroidBug5497Workaround.assistActivity(this);即可。
注意:在setContentView(R.layout.xxx)之后调用。
在AndroidManifest.xml
2.自定义解决方法类:
import android.app.Activity;import android.graphics.Rect;import android.view.View;import android.view.ViewTreeObserver;import android.widget.FrameLayout; public class AndroidBug5497Workaround { public static void assistActivity (Activity activity) { new AndroidBug5497Workaround(activity); } private View mChildOfContent; private int usableHeightPrevious; private FrameLayout.LayoutParams frameLayoutParams; private AndroidBug5497Workaround(Activity activity) { FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content); mChildOfContent = content.getChildAt(0); mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout() { possiblyResizeChildOfContent(); } }); frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams(); } private void possiblyResizeChildOfContent() { int usableHeightNow = computeUsableHeight(); if (usableHeightNow != usableHeightPrevious) { int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight(); int heightDifference = usableHeightSansKeyboard - usableHeightNow; if (heightDifference > (usableHeightSansKeyboard/4)) { // keyboard probably just became visible frameLayoutParams.height = usableHeightSansKeyboard - heightDifference; } else { // keyboard probably just became hidden frameLayoutParams.height = usableHeightSansKeyboard; } mChildOfContent.requestLayout(); usableHeightPrevious = usableHeightNow; } } private int computeUsableHeight() { Rect r = new Rect(); mChildOfContent.getWindowVisibleDisplayFrame(r); return (r.bottom - r.top); } }
更多相关文章
- android包Android "java.lang.NoClassDefFoundError:*"报错的处
- Android 架构解析及驱动 键盘篇
- android使用notifyDataSetChanged()方法,adapter的数据更新了,但是
- Android键盘映射
- Win7 64位 Android SDK下载和更新失败的解决方法
- Android中 int 和 String 互相转换的多种方法
- Android使用webview让服务器上的js调用java代码的方法
- android 读取资源字符串的 方法
- [转]]Android 应用签名提权方法