EditText初始不获得焦点及输入框被遮挡问题

介绍EditText和AutoCompleteTextView初始不获得焦点及解决软键盘弹出时遮挡输入框问题

1、activity启动时EditText不获得焦点
Activity启动时若有一个EditText默认,EditText获得焦点,去掉首次焦点,在manifest.xml中对应activity添加

1

android:windowSoftInputMode="stateHidden"

即可。

2、键盘弹出时输入框被压缩
输入框获得焦点弹出软键盘时,输入框被压缩,字体上浮,同时背景出现问题。如下:

网上解决方法是添加

1

android:windowSoftInputMode="stateHidden|adjustResize"

1

2

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE

| WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

经测试后无效。

解决方法为在外层布局中添加scrollView,因为scrollView只允许包含一个子View,所以如果出现问题布局已有外层layou,直接嵌套在ScrollView中即可,如下:

Java

1

2

3

4

5

6

7

8

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent" >

<!-- your layout -->

</ScrollView>

如果出现问题布局没有外层layout,还需要再嵌套一层RelativeLayout,如下:

Java

1

2

3

4

5

6

7

8

9

10

11

12

13

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent" >

<RelativeLayout

android:layout_width="match_parent"

android:layout_height="match_parent" >

<!-- your layout -->

</RelativeLayout>

</ScrollView>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值