横屏EditText不需要额外的输入框,软键盘判断

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/heming9174/article/details/78802292

不弹出额外的输入框

在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);
    }
}

猜你喜欢

转载自blog.csdn.net/heming9174/article/details/78802292