1)使用ViewPager切換頁面,當使用軟鍵盤輸入時,底部的按鈕視圖會被頂上去。
解決方法:在AndroidManifest.xml中将使用ViewPager的Activity裡添加android:windowSoftInputMode="adjustPan"
如:<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
2)當在某個頁面輸入資訊時彈出軟鍵盤,使用ViewPager切換頁面時,軟鍵盤依舊存在。
解決方法:1、定義兩個變量
private InputMethodManager manager;
private View currentFocus;
2、在onCreate中初始化manager
manager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
3、在ViewPager的事件監聽onPageSelected中定義隐藏輸入法
currentFocus = MainActivity.this.getCurrentFocus();
if(currentFocus != null){
//檢查輸入法是否打開
if(manager.isActive()){
//隐藏軟鍵盤
try {
manager.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
} catch (Exception e) {
e.printStackTrace();
}
}
}