2019独角兽企业重金招聘Python工程师标准>>>
在全屏模式或者是沉寝室标题栏
方案一:全屏模式
1.软键盘被EditText遮挡住了,如果说EditText被嵌套在有滑动的视图中,采取的方式是:
activity中设置此属性
android:windowSoftInputMode="adjustResize"
根视图添加此属性
android:fitsSystemWindows="true"
adjustPan
是把整个界面向上平移,使输入框露出,不会改变界面的布局
2.如果说EditText没有被嵌套在有滑动的视图中,采取的方式是:
activity中设置此属性
android:windowSoftInputMode="adjustPan"
adjustResize
则是重新计算弹出软键盘之后的界面大小,相当于是用更少的界面区域去显示内容,输入框一般自然也就在内了。
3.如果需要进入Activity时隐藏软件盘,采取的方式是:
android:configChanges="keyboardHidden|orientation"
方案二:
public class AndroidBug5497Workaround {// For more information, see https://code.google.com/p/android/issues/detail?id=5497// To use this class, simply invoke assistActivity() on an Activity that already has its content view set.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 visibleframeLayoutParams.height = usableHeightSansKeyboard - heightDifference;} else {// keyboard probably just became hiddenframeLayoutParams.height = usableHeightSansKeyboard;}mChildOfContent.requestLayout();usableHeightPrevious = usableHeightNow;}}private int computeUsableHeight() {Rect r = new Rect();mChildOfContent.getWindowVisibleDisplayFrame(r);return (r.bottom - r.top);// 全屏模式下: return r.bottom}}
代码使用方式:
- 把
AndroidBug5497Workaround
类复制到项目中 - 在需要填坑的activity的onCreate方法中添加一句
AndroidBug5497Workaround.assistActivity(this)
即可。
4.隐藏软键盘
android:clickable="true"android:focusableInTouchMode="true"