教你解決android軟鍵盤擋住輸入框問題!

來源:互聯網
上載者:User

大家在布局時候,有時候會發現輸入框被擋住一部分,能完全顯示出來,但是系統內建簡訊介面
可以完全漂浮在軟鍵盤之上,看了一下簡訊源碼,修改一下輸入模式就可以了,源碼如下
代碼方式:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
                WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

也可以簡單點:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
  xml方式:
<activity android:name=".Activity.FilterActivity" android:label="@string/app_name"  android:windowSoftInputMode="stateHidden" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation"
           />

下面做個詳細的介紹:

軟IME模式選項:
public int softInputMode;

以下選項與IME模式有關:
軟輸入地區是否可見。
public static final int SOFT_INPUT_MASK_STATE = 0x0f;

未指定狀態。
public static final int SOFT_INPUT_STATE_UNSPECIFIED = 0;

不要修改軟IME地區的狀態。
public static final int SOFT_INPUT_STATE_UNCHANGED = 1;

隱藏IME地區(當使用者進入視窗時)。
public static final int SOFT_INPUT_STATE_HIDDEN = 2;

當視窗獲得焦點時,隱藏IME地區。
public static final int SOFT_INPUT_STATE_ALWAYS_HIDDEN = 3;

顯示IME地區(當使用者進入視窗時)。
public static final int SOFT_INPUT_STATE_VISIBLE = 4;

當視窗獲得焦點時,顯示IME地區。
public static final int SOFT_INPUT_STATE_ALWAYS_VISIBLE = 5;

視窗應當主動調整,以適應軟輸入視窗。
public static final int SOFT_INPUT_MASK_ADJUST = 0xf0;

未指定狀態,系統將根據視窗內容嘗試選擇一個IME樣式。
public static final int SOFT_INPUT_ADJUST_UNSPECIFIED = 0x00;

當IME顯示時,允許視窗重新計算尺寸,使內容不被IME所覆蓋。
不可與SOFT_INPUT_ADJUSP_PAN混合使用;如果兩個都沒有設定,系統將根據視窗內容自動化佈建一個選項。
public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10;

IME顯示時平移視窗。它不需要處理尺寸變化,架構能夠移動視窗以確保輸入焦點可見。
不可與SOFT_INPUT_ADJUST_RESIZE混合使用;如果兩個都沒有設定,系統將根據視窗內容自動化佈建一個選項。
public static final int SOFT_INPUT_ADJUST_PAN = 0x20;

當使用者轉至此視窗時,由系統自動化佈建,所以你不要設定它。
當視窗顯示之後該標誌自動清除。
public static final int SOFT_INPUT_IS_FORWARD_NAVIGATION = 0x100;

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.