*本篇文章已受權微信公衆號 guolin_blog (郭霖)獨家發佈java
在開發中,常常會遇到鍵盤擋住輸入框的狀況,好比登陸界面或註冊界面,彈出的軟鍵盤把登陸或註冊按鈕擋住了,用戶必須把軟鍵盤收起,才能點擊相應按鈕,這樣的用戶體驗很是很差。像微信則直接把登陸按鈕作在輸入框的上面,但有不少狀況下,這常常知足不了需求。同時若是輸入框特別多的狀況下,點擊輸入時,當前輸入框沒被擋住,可是當前輸入框下面的輸入框卻沒法獲取焦點,必須先把鍵盤收起,再去獲取下面輸入框焦點,這樣用戶體驗也很是很差,那有什麼辦法呢?
系統的adjustResize和adjustPan有什麼區別,他們使用時的注意事項,有什麼系統要求及蔽端呢?android
下面對幾種在開發中經常使用的方法進行總結:windows
主要實現方法:
在AndroidManifest.xml對應的Activity裏添加
android:windowSoftInputMode=」adjustPan」或是android:windowSoftInputMode=」adjustResize」屬性
這兩種屬性的區別,官方的解釋是:
微信
這兩個屬性做用都是爲了調整界面使鍵盤不擋住輸入框 ,我這裏對這兩種屬性使用場景、優缺點、注意事項進行了全方面總結,不知你們平時使用時是否注意到了。ide
屬性 | 注意事項 | 優缺點 | 失效狀況 | 適用狀況 |
---|---|---|---|---|
adjustResize | 須要界面自己可調整尺寸, 如在佈局添加ScrollView,或輸入控件屬於RecycleView/ListView某一項 |
優勢:1.不會把標題欄頂出當前佈局; 2.有多項輸入時,當前輸入框下面的輸入框可上下滑動輸入 缺點:1.須要界面自己可調整尺寸; 2. 全屏時失效 |
1.Activity主窗口尺寸沒法調整; 2.Activity全屏 3.android5.0以上經過style設置沉浸式狀態欄模式而不設置fitSystemWindow爲true |
非全屏或是非沉浸式狀態欄輸入界面,輸入框比較多 |
adjustPan | 頁面不會從新佈局,當前輸入框和鍵盤會直接將當前輸入框以上界面總體向上平移,這樣即便界面包含標題欄,也會被頂上去 | 優勢: 使用簡單,不須要界面自己可調整尺寸,不會有失效狀況 缺點: 會把標題欄頂出當前佈局;有多項輸入時,當前輸入框下面的輸入框沒法輸入,必須收起鍵盤顯示輸入框再輸入 |
無 | 有少許輸入項,且輸入量居界面上方 |
fitsSystemWindows | 若是多個View設置了fitsSystemWindows=」true」,只有初始的view起做用,都是從第一個設置了fitsSystemWindows的view開始計算padding | 優勢:使用簡單,須要沉浸式狀態欄的界面,不須要本身計算padding狀態欄的高度 缺點:使用有限制 |
1.View 的其餘 padding 值被從新改寫了 2.手機系統版本>=android 4.4 |
1.界面全屏 2.設置界面主題爲沉浸式狀態欄 |
假設原始界面是一個LinearLayout包含若干EditText,以下圖所示,在分別使用兩種屬性時的表現。工具
整個界面向上平移,使輸入框露出,它不會改變界面的佈局;界面總體可用高度仍是屏幕高度,這個能夠經過下面的截圖看出,如點擊輸入框6,輸入框會被推到鍵盤上方,但輸入框1被頂出去了,若是界面包含標題欄,也會被頂出去。佈局
須要界面的高度是可變的,或者說Activity主窗口的尺寸是能夠調整的,若是不能調整,則不會起做用。
例如:Activity的xml佈局中只有一個LinearLayout包含若干EditText,在Activity的AndroidMainfest.xml中設置android:windowSoftInputMode=」adjustResize」屬性,點擊輸入框6, 發現軟鍵盤擋住了輸入框6,並無調整,以下圖所示:post
但使用這兩種屬性,咱們能夠總結如下幾點:
1) 使用adjustPan, 若是須要輸入的項比較多時,點擊輸入框,當前輸入項會被頂到軟鍵盤上方,但若當前輸入框下面還有輸入項時,卻須要先收起鍵盤,再點擊相應的輸入項才能輸入。這樣操做太繁瑣了,對於用戶體驗不大好;
2) adjustResize的使用,須要界面自己可顯示的窗口內容能調整,可結合scrollview使用;ui
在相應界面的xml佈局中,最外層添加一個ScrollView,不在AndroidMainfest.xml中設置任何android:windowSoftInputMode屬性,此時點擊輸入框,輸入框均不會被軟鍵盤檔住。即便當前輸入框下方也有輸入框,在鍵盤顯示的狀況下,也能夠經過上下滑動界面來輸入,而不用先隱藏鍵盤,點擊下方輸入框,再顯示鍵盤輸入。
咱們能夠根據Android Studio的Inspect Layout工具來查看界面真正佔用的佈局高度,工具在
this
經過該工具,咱們看到:
界面真正能用的高度=屏幕高度-狀態欄高度-軟鍵盤高度
界面中藍框是真正界面所用的高度:
咱們再在該類的AndroidMainfest.xml中設置windowSoftInputMode屬性爲adjustPan,
<activity android:name=".TestInputActivity" android:windowSoftInputMode="adjustPan">
發現當前輸入框不會被擋住,可是輸入框比較多時,在有鍵盤顯示時,界面上下滑動,但只能滑動部分,且若是輸入框在界面靠下方時,點擊輸入框,標題欄也會被頂出去,以下圖所示:
咱們藉助Inspect Layout工具查看此設置佈局可用高度,從下圖能夠看出,此時佈局可用高度是屏幕的高度,上下滑動也只是此屏的高度,在輸入框9如下的輸入框滑不出來,向上滑動,也只能滑到輸入框1。
咱們前面說過adjustResize的使用必須界面佈局高度是可變的,如最外層套個ScrollView或是界面可收縮的,才起做用。這裏在該類的AndroidMainfest.xml中設置windowSoftInputMode屬性爲adjustResize,
<activity android:name=".TestInputActivity" android:windowSoftInputMode="adjustResize">
發現效果和1不設置任何windowSoftInputMode屬性相似,其使用高度也是:屏幕高度-狀態欄高度-軟鍵盤高度
咱們再來看看windowSoftInputMode默認屬性值stateUnspecified:
能夠看出,系統將選擇合適的狀態,也就是在界面最外層包含一層ScrollView時,設置默認屬性值stateUnspecified其實就是adjustResize屬性。
但如下兩方面沒法知足需求:
1) 當Activity設置成全屏fullscreen模式時或是使用沉浸式狀態欄時,界面最外層包裹 ScrollView,當輸入框超過一屏,當前輸入框下面的輸入框並不能上下滑動來輸入,狀況相似於ScrollView+adjustPan,只能滑動部分,經過Inspect Layout也能夠看到,界面可用高度是整個屏幕高度,並不會進行調整高度。即便設置adjustResize,也不起做用。
2) 若是是相似於註冊界面或是登陸界面,鍵盤會擋住輸入框下面的登陸按鈕。
自android系統4.4(API>=19)就開始支持沉浸式狀態欄,當使用覺System windows(系統窗口),顯示系統一些屬性和操做區域,如 最上方的狀態及沒有實體按鍵的最下方的虛擬導航欄。
android:fitsSystemWindows=「true」會使得屏幕上的可佈局空間位於狀態欄下方與導航欄上方
使用場景:針對界面全屏或是沉浸式狀態欄,輸入框不會被鍵盤遮擋。主要用於一些登陸界面,或是須要把界面總體都頂上去的場景。
(1) 獲取Activity佈局xml的最外層控件,如xml文件以下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/main" tools:context="com.example.liubin1.softkeyboardhelper.MainActivity"> <EditText android:id="@+id/name" android:hint="請輸入用戶名:" android:layout_centerInParent="true" android:layout_width="match_parent" android:layout_height="50dp" /> <EditText android:id="@+id/pas" android:layout_below="@id/name" android:hint="請輸入密碼:" android:layout_centerInParent="true" android:layout_width="match_parent" android:layout_height="50dp" /> <Button android:id="@+id/login_btn" android:layout_below="@id/rpas" android:layout_centerHorizontal="true" android:text="登陸" android:layout_width="180dp" android:layout_height="50dp" /> </RelativeLayout>
先獲取到最外層控件
RelativeLayout main = (RelativeLayout) findViewById(R.id.main);
(2) 獲取到最後一個控件,如上面的xml文件,最後一個控件是Button
Button login_btn = (Button) findViewById(R.id.login_btn);
(3) 給最外層控件和最後一個控件添加監聽事件
//在Activity的onCreate裏添加以下方法 addLayoutListener(main,login_btn); /** * addLayoutListener方法以下 * @param main 根佈局 * @param scroll 須要顯示的最下方View */ public void addLayoutListener(final View main, final View scroll) { main.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect rect = new Rect(); //一、獲取main在窗體的可視區域 main.getWindowVisibleDisplayFrame(rect); //二、獲取main在窗體的不可視區域高度,在鍵盤沒有彈起時,main.getRootView().getHeight()調節度應該和rect.bottom高度同樣 int mainInvisibleHeight = main.getRootView().getHeight() - rect.bottom; int screenHeight = main.getRootView().getHeight();//屏幕高度 //三、不可見區域大於屏幕自己高度的1/4:說明鍵盤彈起了 if (mainInvisibleHeight > screenHeight / 4) { int[] location = new int[2]; scroll.getLocationInWindow(location); // 4、獲取Scroll的窗體座標,算出main須要滾動的高度 int srollHeight = (location[1] + scroll.getHeight()) - rect.bottom; //5、讓界面總體上移鍵盤的高度 main.scrollTo(0, srollHeight); } else { //三、不可見區域小於屏幕高度1/4時,說明鍵盤隱藏了,把界面下移,移回到原有高度 main.scrollTo(0, 0); } } }); } }
此方法經過監聽Activity最外層佈局控件來檢測軟鍵盤是否彈出,而後去手動調用控件的scrollTo方法達到調整佈局目的。
具體實現代碼見demo中的LoginActivity類。
此種方法須要在當前界面寫比較多的代碼,在某些手機上,若輸入時,軟鍵盤高度是可變的,如中英文切換,高度變化時,會發現適配的不大好。以下圖:
從上圖能夠看出,若是鍵盤高度變化,鍵盤仍是會擋住登陸按鈕。
此方法主要是經過在須要移動的控件外套一層scrollView,同時最佈局最外層使用自定義view監聽鍵盤彈出狀態,計算鍵盤高度,再進行計算須要移動的位置,這個和方法三有點相似,但能適配鍵盤高度變化狀況。
(1) 先寫自定義View,實時臨聽界面鍵盤彈起狀態,計算鍵盤高度
public class KeyboardLayout extends FrameLayout { private KeyboardLayoutListener mListener; private boolean mIsKeyboardActive = false; //輸入法是否激活 private int mKeyboardHeight = 0; // 輸入法高度 public KeyboardLayout(Context context) { this(context, null, 0); } public KeyboardLayout(Context context, AttributeSet attrs) { this(context, attrs, 0); } public KeyboardLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // 監聽佈局變化 getViewTreeObserver().addOnGlobalLayoutListener(new KeyboardOnGlobalChangeListener()); } public void setKeyboardListener(KeyboardLayoutListener listener) { mListener = listener; } public KeyboardLayoutListener getKeyboardListener() { return mListener; } public boolean isKeyboardActive() { return mIsKeyboardActive; } /** * 獲取輸入法高度 * * @return */ public int getKeyboardHeight() { return mKeyboardHeight; } public interface KeyboardLayoutListener { /** * @param isActive 輸入法是否激活 * @param keyboardHeight 輸入法面板高度 */ void onKeyboardStateChanged(boolean isActive, int keyboardHeight); } private class KeyboardOnGlobalChangeListener implements ViewTreeObserver.OnGlobalLayoutListener { int mScreenHeight = 0; private int getScreenHeight() { if (mScreenHeight > 0) { return mScreenHeight; } mScreenHeight = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay().getHeight(); return mScreenHeight; } @Override public void onGlobalLayout() { Rect rect = new Rect(); // 獲取當前頁面窗口的顯示範圍 ((Activity) getContext()).getWindow().getDecorView().getWindowVisibleDisplayFrame(rect); int screenHeight = getScreenHeight(); int keyboardHeight = screenHeight - rect.bottom; // 輸入法的高度 boolean isActive = false; if (Math.abs(keyboardHeight) > screenHeight / 4) { isActive = true; // 超過屏幕五分之一則表示彈出了輸入法 mKeyboardHeight = keyboardHeight; } mIsKeyboardActive = isActive; if (mListener != null) { mListener.onKeyboardStateChanged(isActive, keyboardHeight); } } } }
(2) xml文件編寫,在界面最外層套上自定義view,在須要滾動的控件外層添加scrollView
<com.example.smilexie.softboradblockedittext.util.KeyboardLayout android:id="@+id/main_ll" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/login_bg" android:orientation="vertical"> <ScrollView android:id="@+id/login_ll" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:layout_marginRight="50dp" android:layout_marginTop="200dp" android:background="@mipmap/login_input_field_icon" android:orientation="horizontal"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginLeft="20dp" android:background="@mipmap/login_yonghuming_icon" /> <EditText android:id="@+id/ui_username_input" style="@style/editext_input_style" android:layout_marginLeft="40dp" android:layout_marginRight="20dp" android:background="@null" android:hint="@string/login_hint_username" android:imeOptions="actionNext" android:textColor="@android:color/white" android:textColorHint="@android:color/white"> <requestFocus /> </EditText> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:layout_marginRight="50dp" android:layout_marginTop="20dp" android:background="@mipmap/login_input_field_icon" android:orientation="horizontal"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginLeft="20dp" android:background="@mipmap/login_mima_icon" /> <EditText android:id="@+id/ui_password_input" style="@style/editext_input_style" android:layout_marginLeft="40dp" android:layout_marginRight="20dp" android:background="@null" android:hint="@string/login_hint_pwd" android:imeOptions="actionDone" android:inputType="textPassword" android:textColor="@android:color/white" android:textColorHint="@android:color/white"></EditText> </LinearLayout> <Button android:id="@+id/login_btn" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:layout_marginRight="50dp" android:layout_marginTop="20dp" android:background="@mipmap/login_button_bg_icon" android:text="@string/login" android:textColor="@color/titlebar_main_color" android:textSize="@dimen/font_normal" /> </LinearLayout> </ScrollView> </com.example.smilexie.softboradblockedittext.util.KeyboardLayout>
(3) Activity調用,自定義view控件添加鍵盤響應,在鍵盤變化時調用scrollView的smoothScrollTo去滾動界面
/** * 監聽鍵盤狀態,佈局有變化時,靠scrollView去滾動界面 */ public void addLayoutListener() { bindingView.mainLl.setKeyboardListener(new KeyboardLayout.KeyboardLayoutListener() { @Override public void onKeyboardStateChanged(boolean isActive, int keyboardHeight) { Log.e("onKeyboardStateChanged", "isActive:" + isActive + " keyboardHeight:" + keyboardHeight); if (isActive) { scrollToBottom(); } } }); } /** * 彈出軟鍵盤時將SVContainer滑到底 */ private void scrollToBottom() { bindingView.loginLl.postDelayed(new Runnable() { @Override public void run() { bindingView.loginLl.smoothScrollTo(0, bindingView.loginLl.getBottom() + SoftKeyInputHidWidget.getStatusBarHeight(LoginActivityForDiffkeyboardHeight.this)); } }, 100); }
具體實現代碼見demo中的LoginActivityForDiffkeyboardHeight類。實現效果以下:
能夠看到鍵盤高度變化了,也不會影響界面佈局
此方法的實現來自android中提出的issue 5497 https://code.google.com/p/android/issues/detail?id=5497
使用場景:針對界面全屏或是沉浸式狀態欄,界面包含比較多輸入框,界面即便包裹了一層ScrollView,在鍵盤顯示時,當前輸入框下面的輸入不能經過上下滑動界面來輸入。
感謝下面提出評論的同窗,指出此方法的不適配問題,以前寫的博文在華爲小米手機上確實有不適配狀況,在輸入時,鍵盤有時會錯亂,如今已加入適配。
1、把SoftHideKeyBoardUtil類複製到項目中;
2、在須要使用的Activity的onCreate方法中添加:SoftHideKeyBoardUtil.assistActivity(this);便可。
SoftHideKeyBoardUtil類具體代碼以下:
/** * 解決鍵盤檔住輸入框 * Created by SmileXie on 2017/4/3. */ public class SoftHideKeyBoardUtil { public static void assistActivity (Activity activity) { new SoftHideKeyBoardUtil(activity); } private View mChildOfContent; private int usableHeightPrevious; private FrameLayout.LayoutParams frameLayoutParams; //爲適應華爲小米等手機鍵盤上方出現黑條或不適配 private int contentHeight;//獲取setContentView原本view的高度 private boolean isfirst = true;//只用獲取一次 private int statusBarHeight;//狀態欄高度 private SoftHideKeyBoardUtil(Activity activity) { //1、找到Activity的最外層佈局控件,它實際上是一個DecorView,它所用的控件就是FrameLayout FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content); //2、獲取到setContentView放進去的View mChildOfContent = content.getChildAt(0); //3、給Activity的xml佈局設置View樹監聽,當佈局有變化,如鍵盤彈出或收起時,都會回調此監聽 mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { //4、軟鍵盤彈起會使GlobalLayout發生變化 public void onGlobalLayout() { if (isfirst) { contentHeight = mChildOfContent.getHeight();//兼容華爲等機型 isfirst = false; } //5、當前佈局發生變化時,對Activity的xml佈局進行重繪 possiblyResizeChildOfContent(); } }); //6、獲取到Activity的xml佈局的放置參數 frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams(); } // 獲取界面可用高度,若是軟鍵盤彈起後,Activity的xml佈局可用高度須要減去鍵盤高度 private void possiblyResizeChildOfContent() { //1、獲取當前界面可用高度,鍵盤彈起後,當前界面可用佈局會減小鍵盤的高度 int usableHeightNow = computeUsableHeight(); //2、若是當前可用高度和原始值不同 if (usableHeightNow != usableHeightPrevious) { //3、獲取Activity中xml中佈局在當前界面顯示的高度 int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight(); //4、Activity中xml佈局的高度-當前可用高度 int heightDifference = usableHeightSansKeyboard - usableHeightNow; //5、高度差大於屏幕1/4時,說明鍵盤彈出 if (heightDifference > (usableHeightSansKeyboard/4)) { // 6、鍵盤彈出了,Activity的xml佈局高度應當減去鍵盤高度 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ frameLayoutParams.height = usableHeightSansKeyboard - heightDifference + statusBarHeight; } else { frameLayoutParams.height = usableHeightSansKeyboard - heightDifference; } } else { frameLayoutParams.height = contentHeight; } //7、 重繪Activity的xml佈局 mChildOfContent.requestLayout(); usableHeightPrevious = usableHeightNow; } } private int computeUsableHeight() { Rect r = new Rect(); mChildOfContent.getWindowVisibleDisplayFrame(r); // 全屏模式下:直接返回r.bottom,r.top實際上是狀態欄的高度 return (r.bottom - r.top); } }
它的實現原理主要是:
(1) 找到Activity的最外層佈局控件,咱們知道全部的Activity都是DecorView,它就是一個FrameLayout控件,該控件id是系統寫死叫R.id.content,就是咱們setContentView時,把相應的View放在此FrameLayout控件裏
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
因此content.getChildAt(0)獲取到的mChildOfContent,也就是咱們用setContentView放進去的View。
(2) 給咱們的Activity的xml佈局View設置一個Listener監聽
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener({ possiblyResizeChildOfContent(); });
View.getViewTreeObserver()能夠獲取一個ViewTreeObserver對象——它是一個觀察者,用以監聽當前View樹所發生的變化。這裏所註冊的addOnGlobalLayoutListener,就是會在當前的View樹的全局佈局(GlobalLayout)發生變化、或者其中的View可視狀態有變化時,進行通知回調。『軟鍵盤彈出/隱 』都能監聽到。
(3) 獲取當前界面可用高度
private int computeUsableHeight() { Rect rect = new Rect(); mChildOfContent.getWindowVisibleDisplayFrame(rect); // rect.top實際上是狀態欄的高度,若是是全屏主題,直接 return rect.bottom就能夠了 return (rect.bottom - rect.top); }
以下圖所示:
(4) 重設高度, 咱們計算出的可用高度,是目前在視覺效果上能看到的界面高度。但當前界面的實際高度是比可用高度要多出一個軟鍵盤的距離的。
具體實現代碼見demo中的TransStatusbarWisthAssistActivity類。
注意:若是既使用了沉浸式狀態欄,又加了fitSystetemWindow=true屬性,就須要在AndroidMainfest.xml註冊Activity的地方添加上如下屬性。由於你兩種都用,系統不知道用哪一種了。fitSystetemWindow已經有resize屏幕的做用。
android:windowSoftInputMode="stateHidden|adjustPan"
經過上面的這種方法,通常佈局輸入鍵盤擋住輸入框的問題基本都能解決。即便界面全屏或是沉浸式狀態欄狀況。
下面對上面幾種方法進行對比:
方法一:優勢:使用簡單,只需在Activity的AndroidMainfest.xml中設置windowSoftInput屬性便可。
注意點:adjustResize屬性必需要界面大小能夠自身改變;
缺點:當輸入框比較多時,當前輸入框下方的輸入框會初鍵盤擋住,須收起鍵盤再進入輸入;使用adjustPan,輸入框較多時,因它是把界面當成一個總體,只會顯示一屏的高度,會把ActionBar頂上去。
方法二:優勢:使用簡單,只需在Activity的最外層佈局包裹一個ScrollView便可。
注意點:不可以使用adjustPan屬性,不然ScrollView失效;
缺點:對於全屏時,在鍵盤顯示時,沒法上下滑動界面達到輸入的目的;
方法三:優勢:能夠解決全屏時,鍵盤擋入按鈕問題。
缺點:只要有此需求的Activity均須要獲取到最外層控件和最後一個控件,監測鍵盤是否彈出,再調用控件的scrollTo方法對界面總體上移或是下移。代碼冗餘。對於鍵盤高度變化時,適配很差。
方法四:優勢:能夠解決全屏時,鍵盤擋入按鈕問題。
缺點:只要有此需求的Activity均須要獲取到最外層控件和最後一個控件,佈局多出一層。
方法五:優勢:能夠解決全屏時,鍵盤擋入輸入框問題。只須要寫一個全局類,其餘有需求的界面直接在onCreate方法裏調用此類的全局方法,便可。
缺點:多用了一個類。
綜上所述: 1) 當輸入框比較少時,界面只有一個輸入框時,能夠經過方法一設置adjustPan; 2) 若是對於非全屏/非沉浸式狀態欄需求,只須要使用方法二ScrollView+adjustResize; 3) 若是對於使用沉浸式狀態欄,使用fitSystemWindow=true屬性,按道理android系統已經作好適配,鍵盤不會擋住輸入框; 4) 若是全屏/沉浸式狀態欄界面,相似於登陸界面,有須要把登陸鍵鈕或是評論按鈕也頂起,若是鍵盤沒有變化需求,可使用方法三,若須要適配鍵盤高度變化,則須要使用方法四; 5) 若是界面使用全屏或沉浸式狀態欄,沒有使用fitSystemWindow=true屬性,通常如須要用到抽屈並且狀態欄顏色也須要跟着變化,則選擇方法五更恰當。