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"
?