android软键盘覆盖了底表中recyclerview中的edittext

use*_*027 1 android android-softkeyboard bottom-sheet

我有几个EditTextRecyclerView那里面是一个BottomSheetDialog。我现在的问题是,当BottomSheetDialog屏幕上显示,我轻按例如7 EditTextRecyclerView。软键盘出现并覆盖EditText,所以我看不到我输入的内容。但是如果我BottomSheetDialog向上拖动一点,EditText即使我点击EditText屏幕上的最后一个,也不会被软键盘覆盖。RecyclerView在这种情况下肯定会调整大小,但如果我不BottonSheetDialog向上拖动,则不会调整大小。知道为什么吗?我该如何解决这个问题?

这是它的样子。 在此处输入图片说明

主程序

class VH extends RecyclerView.ViewHolder {
    public VH(View itemView) {
        super(itemView);
    }
}

private void test() {
    BSTest bsTest = new BSTest(this);
    bsTest.setContentView(R.layout.bottomsheet_test);
    RecyclerView rv = (RecyclerView) bsTest.findViewById(R.id.recyclerView);
    rv.setLayoutManager(new LinearLayoutManager(this));
    rv.setAdapter(new RecyclerView.Adapter() {
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new VH(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_edittext, parent, false));
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        }

        @Override
        public int getItemCount() {
            return 20;
        }
    });
    bsTest.show();
}
Run Code Online (Sandbox Code Playgroud)

BSTest.java

public class BSTest extends BottomSheetDialog {
    public BSTest(@NonNull Context context) {
        super(context);
    }

    private BSTest(@NonNull Context context, @StyleRes int theme) {
        super(context, theme);
    }

    private BSTest(@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }
}
Run Code Online (Sandbox Code Playgroud)

bottomsheet_test.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="1"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="2"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="3"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

item_edittext.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="1"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="2"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="3"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

LOG*_*TAG 5

使用这个 KeyboardUtil 作为新的解决方案!

在 BottomSheetFragment 的 onCreateDialog 中使用它

KeyboardUtil(getActivity(), view);
Run Code Online (Sandbox Code Playgroud)

或者

片段使用

new KeyboardUtil(this, findViewById(R.id.fragment_container));
Run Code Online (Sandbox Code Playgroud)

通过使用这个 Util 类

https://github.com/mikepenz/MaterialDrawer/blob/aa9136fb4f5b3a80460fe5f47213985026d20c88/library/src/main/java/com/mikepenz/materialdrawer/util/KeyboardUtil.java

信用:迈克彭兹