Android中EditText被输入法软键盘遮挡的完美解决方案(非全屏模式下)

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

1、不要给EditText的背景设置为@null 清单文件中为activity设置属性 代码中设置显示输入法

android:windowSoftInputMode=”stateVisible|adjustResize”

/**
 * 展示输入法输入框
 */
public void showKeyBoard() {
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}

2、设置一个透明的背景:input_edit_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
       android:drawable="@color/transparent"
       android:insetLeft="0dp"
       android:insetRight="0dp"
       android:insetTop="10dp"
       android:insetBottom="10dp">
</inset>

3、在布局文件中使用当前背景设置给EditText

<EditText
    android:id="@+id/et_input"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/input_edit_bg"
    android:singleLine="true"
    android:textSize="@dimen/input_text_size"/>

猜你喜欢

转载自blog.csdn.net/u010838785/article/details/82146980