橫屏EditText不需要額外的輸入框,軟鍵盤判斷
阿新 • • 發佈:2019-01-07
不彈出額外的輸入框
在edittext輸入的時候,因為是橫屏模式,額外彈出的輸入框導致頁面看著特別醜…
解決辦法:
在editText xml屬性加一條
android:imeOptions="flagNoExtractUi"
確實不會彈出了,但是….
特麼剛剛進入頁面,editText就自動獲得焦點,自動彈出小鍵盤了.
解決辦法:
在editText父類佈局xml屬性上面新增
android:focusable="true"
android:focusableInTouchMode="true"
橫屏狀態軟鍵盤操作
判斷軟鍵盤狀態 && 彈出收縮軟鍵盤
public class SoftKeyBoardUtil {
/**
* 判斷軟鍵盤是否彈出(適用於橫屏)
*/
public static boolean isOpen(Activity activity) {
//獲取當前螢幕內容的高度
int screenHeight = activity.getWindow().getDecorView().getHeight();
//獲取View可見區域的bottom
Rect rect = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
return screenHeight - rect.bottom != 0;
}
/**
* 開啟Or關閉 軟鍵盤
*/
public static void hideKeyboard(Context context) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
}