设置EditText不自动获取焦点

xiaoxiao2021-02-28  90

强迫症,产品设计中没有这个需求,但是个人感觉进来直接就弹出键盘很不爽。

说一下方法:

1.在布局文件中操作

在editText的上一层布局中,添加2个属性,如下:

android:focusable="true"

android:focusableInTouchMode="true"

记住要在EditText的上一级控件中写!

2.在代码中操作:

就是使用clearFocus();方法

InputMethodManager  ipt = (InputMethodManager  )getSystemService(Context.INPUT_METHOD_SERVICE);

ipt.hideSoftInputFromWindow(editText控件.getWindowToken(),0);//关闭软键盘

个人建议使用第一种方法,简单便捷

转载请注明原文地址: https://www.6miu.com/read-68041.html

最新回复(0)