歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android虛擬鍵盤彈出時擋住EditText解決方法

Android虛擬鍵盤彈出時擋住EditText解決方法

日期:2017/3/1 10:26:20   编辑:Linux編程

在manifest的activity節點使用 Xml代碼

<activity Android:windowSoftInputMode="adjustResize"/>

android:windowSoftInputMode的使用。

activity如何與軟鍵盤交互。這個屬性的設置將會影響兩件事情:

1> 軟鍵盤的狀態——是否它是隱藏或顯示——當活動(Activity)成為用戶關注的焦點。

2> 活動的主窗口調整——是否減少活動主窗口大小以便騰出空間放軟鍵盤或是否當活動窗口的部分被軟鍵盤覆蓋時它的內容的當前焦點是可見的。

要默認隱藏輸入法

  1. <activity
  2. android:name="ViewActivity"
  3. android:label="@string/app_name"
  4. android:windowSoftInputMode="adjustUnspecified|stateHidden"
  5. android:configChanges="orientation|keyboardHidden">
  6. </activity>

果要默認顯示輸入法

  1. <activity
  2. android:name="ViewActivity"
  3. android:label="@string/app_name"
  4. android:windowSoftInputMode="stateVisible "
  5. android:configChanges="orientation|keyboardHidden">
  6. </activity>

2:

有些手機可能用上訴方法無法奏效,那可以用以下方法:

在EditText的布局文件裡添加ScrollView,當點擊EditText時控件會滑動,當失去焦點時滾動條會隱藏。

Copyright © Linux教程網 All Rights Reserved