# AndroidEditTextDemo
**Repository Path**: mailiang/AndroidEditTextDemo
## Basic Information
- **Project Name**: AndroidEditTextDemo
- **Description**: No description available
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-11-13
- **Last Updated**: 2020-12-18
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# AndroidEditTextDemo
[CSDN博客](https://mailiang.blog.csdn.net/article/details/102043717)
当跳转到带有EditText的界面后,App会自动弹出输入法,严重影响了用户体验。因此,我们有时候需要取消EditText的默认聚焦。
**方法一:**
在EditText的父控件中加上这两行代码:
```
android:focusable="true"
android:focusableInTouchMode="true"
```
例如:
```
//
```
**方法二:**
使用代码使外层组件获取焦点,代码如下:
```
View.setFocusable(true);
View.setFocusableInTouchMode(true);
View.requestFocus();//有时需要添加,谨慎起见建议全部都加
```
示例:
```
布局文件:
代码:
LinearLayout ll = findViewById(R.id.ll);
ll.setFocusable(true);
ll.setFocusableInTouchMode(true);
ll.requestFocus();
```
**方法三:**
将该窗口下的输入法隐藏起来,代码如下(仅隐藏输入法,需要在setContentView()前调用):
```
this.getWindow()
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
```
示例:
```
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow()
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
setContentView(R.layout.activity_method3);
}
```
**方法四:**
在AndroidManifest相应的Activity中添加如下代码(仅隐藏输入法):
```
android:configChanges="keyboardHidden|orientation"
android:windowSoftInputMode="adjustResize|stateHidden"
```
示例:
```
```